Skip to content

Commit 330c163

Browse files
committed
chore(release): Release version 0.10.3
2 parents b61cf9b + 9538bdd commit 330c163

File tree

8 files changed

+152
-8
lines changed

8 files changed

+152
-8
lines changed

.bumpversion.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0 OR MIT
44

55
[tool.bumpversion]
6-
current_version = "0.10.2"
6+
current_version = "0.10.3"
77

88
[[tool.bumpversion.files]]
99
filename = "README.md"

CHANGELOG.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ All notable changes to this project will be documented in this file.
1414
The format is based on https://keepachangelog.com/[Keep a Changelog], and this
1515
project adheres to https://semver.org/[Semantic Versioning].
1616

17+
== {compare-url}/v0.10.2\...v0.10.3[0.10.3] - 2024-11-09
18+
19+
=== Added
20+
21+
* Add `FileTime::to_ne_bytes` and `FileTime::from_ne_bytes`
22+
({pull-request-url}/243[#243])
23+
1724
== {compare-url}/v0.10.1\...v0.10.2[0.10.2] - 2024-11-08
1825

1926
=== Changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[package]
66
name = "nt-time"
7-
version = "0.10.2"
7+
version = "0.10.3"
88
authors = ["Shun Sakai <[email protected]>"]
99
edition = "2021"
1010
rust-version = "1.67.0"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Add this to your `Cargo.toml`:
2020

2121
```toml
2222
[dependencies]
23-
nt-time = "0.10.2"
23+
nt-time = "0.10.3"
2424
```
2525

2626
### Crate features

benches/file_time.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ fn to_le_bytes(b: &mut Bencher) {
3737
b.iter(|| FileTime::NT_TIME_EPOCH.to_le_bytes());
3838
}
3939

40+
#[bench]
41+
fn to_ne_bytes(b: &mut Bencher) {
42+
b.iter(|| FileTime::NT_TIME_EPOCH.to_ne_bytes());
43+
}
44+
4045
#[bench]
4146
fn from_be_bytes(b: &mut Bencher) {
4247
b.iter(|| FileTime::from_be_bytes([u8::MIN; 8]));
@@ -47,6 +52,11 @@ fn from_le_bytes(b: &mut Bencher) {
4752
b.iter(|| FileTime::from_le_bytes([u8::MIN; 8]));
4853
}
4954

55+
#[bench]
56+
fn from_ne_bytes(b: &mut Bencher) {
57+
b.iter(|| FileTime::from_ne_bytes([u8::MIN; 8]));
58+
}
59+
5060
#[bench]
5161
fn default(b: &mut Bencher) {
5262
b.iter(FileTime::default);

src/file_time.rs

Lines changed: 130 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl FileTime {
106106
}
107107

108108
/// Returns the memory representation of this `FileTime` as a byte array in
109-
/// big-endian byte order.
109+
/// big-endian (network) byte order.
110110
///
111111
/// # Examples
112112
///
@@ -147,8 +147,37 @@ impl FileTime {
147147
self.to_raw().to_le_bytes()
148148
}
149149

150+
/// Returns the memory representation of this `FileTime` as a byte array in
151+
/// native byte order.
152+
///
153+
/// As the target platform's native endianness is used, portable code should
154+
/// use [`FileTime::to_be_bytes`] or [`FileTime::to_le_bytes`], as
155+
/// appropriate, instead.
156+
///
157+
/// # Examples
158+
///
159+
/// ```
160+
/// # use nt_time::FileTime;
161+
/// #
162+
/// assert_eq!(FileTime::NT_TIME_EPOCH.to_ne_bytes(), [u8::MIN; 8]);
163+
/// assert_eq!(
164+
/// FileTime::UNIX_EPOCH.to_ne_bytes(),
165+
/// if cfg!(target_endian = "big") {
166+
/// [0x01, 0x9d, 0xb1, 0xde, 0xd5, 0x3e, 0x80, 0x00]
167+
/// } else {
168+
/// [0x00, 0x80, 0x3e, 0xd5, 0xde, 0xb1, 0x9d, 0x01]
169+
/// }
170+
/// );
171+
/// assert_eq!(FileTime::MAX.to_ne_bytes(), [u8::MAX; 8]);
172+
/// ```
173+
#[must_use]
174+
#[inline]
175+
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
176+
self.to_raw().to_ne_bytes()
177+
}
178+
150179
/// Creates a native endian `FileTime` value from its representation as a
151-
/// byte array in big-endian.
180+
/// byte array in big endian.
152181
///
153182
/// # Examples
154183
///
@@ -172,7 +201,7 @@ impl FileTime {
172201
}
173202

174203
/// Creates a native endian `FileTime` value from its representation as a
175-
/// byte array in little-endian.
204+
/// byte array in little endian.
176205
///
177206
/// # Examples
178207
///
@@ -194,6 +223,38 @@ impl FileTime {
194223
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
195224
Self::new(u64::from_le_bytes(bytes))
196225
}
226+
227+
/// Creates a native endian `FileTime` value from its memory representation
228+
/// as a byte array in native endianness.
229+
///
230+
/// As the target platform's native endianness is used, portable code likely
231+
/// wants to use [`FileTime::from_be_bytes`] or [`FileTime::from_le_bytes`],
232+
/// as appropriate instead.
233+
///
234+
/// # Examples
235+
///
236+
/// ```
237+
/// # use nt_time::FileTime;
238+
/// #
239+
/// assert_eq!(
240+
/// FileTime::from_ne_bytes([u8::MIN; 8]),
241+
/// FileTime::NT_TIME_EPOCH
242+
/// );
243+
/// assert_eq!(
244+
/// FileTime::from_ne_bytes(if cfg!(target_endian = "big") {
245+
/// [0x01, 0x9d, 0xb1, 0xde, 0xd5, 0x3e, 0x80, 0x00]
246+
/// } else {
247+
/// [0x00, 0x80, 0x3e, 0xd5, 0xde, 0xb1, 0x9d, 0x01]
248+
/// }),
249+
/// FileTime::UNIX_EPOCH
250+
/// );
251+
/// assert_eq!(FileTime::from_ne_bytes([u8::MAX; 8]), FileTime::MAX);
252+
/// ```
253+
#[must_use]
254+
#[inline]
255+
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
256+
Self::new(u64::from_ne_bytes(bytes))
257+
}
197258
}
198259

199260
impl Default for FileTime {
@@ -264,6 +325,12 @@ impl FromStr for FileTime {
264325
mod tests {
265326
use super::*;
266327

328+
#[test]
329+
fn size_of() {
330+
assert_eq!(mem::size_of::<FileTime>(), 8);
331+
assert_eq!(mem::size_of::<FileTime>(), mem::size_of::<u64>());
332+
}
333+
267334
#[test]
268335
fn clone() {
269336
assert_eq!(FileTime::NT_TIME_EPOCH.clone(), FileTime::NT_TIME_EPOCH);
@@ -376,6 +443,33 @@ mod tests {
376443
const _: [u8; 8] = FileTime::NT_TIME_EPOCH.to_le_bytes();
377444
}
378445

446+
#[test]
447+
fn to_ne_bytes() {
448+
assert_eq!(FileTime::NT_TIME_EPOCH.to_ne_bytes(), [u8::MIN; 8]);
449+
assert_eq!(
450+
FileTime::UNIX_EPOCH.to_ne_bytes(),
451+
if cfg!(target_endian = "big") {
452+
[0x01, 0x9d, 0xb1, 0xde, 0xd5, 0x3e, 0x80, 0x00]
453+
} else {
454+
[0x00, 0x80, 0x3e, 0xd5, 0xde, 0xb1, 0x9d, 0x01]
455+
}
456+
);
457+
assert_eq!(FileTime::MAX.to_ne_bytes(), [u8::MAX; 8]);
458+
}
459+
460+
#[cfg(feature = "std")]
461+
#[test_strategy::proptest]
462+
fn to_ne_bytes_roundtrip(ft: FileTime) {
463+
use proptest::prop_assert_eq;
464+
465+
prop_assert_eq!(ft.to_ne_bytes(), ft.to_raw().to_ne_bytes());
466+
}
467+
468+
#[test]
469+
const fn to_ne_bytes_is_const_fn() {
470+
const _: [u8; 8] = FileTime::NT_TIME_EPOCH.to_ne_bytes();
471+
}
472+
379473
#[test]
380474
fn from_be_bytes() {
381475
assert_eq!(
@@ -434,6 +528,39 @@ mod tests {
434528
const _: FileTime = FileTime::from_le_bytes([u8::MIN; 8]);
435529
}
436530

531+
#[test]
532+
fn from_ne_bytes() {
533+
assert_eq!(
534+
FileTime::from_ne_bytes([u8::MIN; 8]),
535+
FileTime::NT_TIME_EPOCH
536+
);
537+
assert_eq!(
538+
FileTime::from_ne_bytes(if cfg!(target_endian = "big") {
539+
[0x01, 0x9d, 0xb1, 0xde, 0xd5, 0x3e, 0x80, 0x00]
540+
} else {
541+
[0x00, 0x80, 0x3e, 0xd5, 0xde, 0xb1, 0x9d, 0x01]
542+
}),
543+
FileTime::UNIX_EPOCH
544+
);
545+
assert_eq!(FileTime::from_ne_bytes([u8::MAX; 8]), FileTime::MAX);
546+
}
547+
548+
#[cfg(feature = "std")]
549+
#[test_strategy::proptest]
550+
fn from_ne_bytes_roundtrip(bytes: [u8; mem::size_of::<FileTime>()]) {
551+
use proptest::prop_assert_eq;
552+
553+
prop_assert_eq!(
554+
FileTime::from_ne_bytes(bytes),
555+
FileTime::new(u64::from_ne_bytes(bytes))
556+
);
557+
}
558+
559+
#[test]
560+
const fn from_ne_bytes_is_const_fn() {
561+
const _: FileTime = FileTime::from_ne_bytes([u8::MIN; 8]);
562+
}
563+
437564
#[test]
438565
fn default() {
439566
assert_eq!(FileTime::default(), FileTime::NT_TIME_EPOCH);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
//! [Unix time]: https://en.wikipedia.org/wiki/Unix_time
8888
//! [MS-DOS date and time]: https://learn.microsoft.com/en-us/windows/win32/sysinfo/ms-dos-date-and-time
8989
90-
#![doc(html_root_url = "https://docs.rs/nt-time/0.10.2/")]
90+
#![doc(html_root_url = "https://docs.rs/nt-time/0.10.3/")]
9191
#![no_std]
9292
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
9393
// Lint levels of rustc.

0 commit comments

Comments
 (0)