@@ -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
199260impl Default for FileTime {
@@ -264,6 +325,12 @@ impl FromStr for FileTime {
264325mod 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 ) ;
0 commit comments