1 #![stable(feature = "metadata_ext", since = "1.1.0")] 2 3 use crate::fs::{self, Metadata}; 4 use crate::sealed::Sealed; 5 use crate::sys_common::{AsInner, AsInnerMut, IntoInner}; 6 use crate::time::SystemTime; 7 8 #[allow(deprecated)] 9 use crate::os::macos::raw; 10 11 /// OS-specific extensions to [`fs::Metadata`]. 12 /// 13 /// [`fs::Metadata`]: crate::fs::Metadata 14 #[stable(feature = "metadata_ext", since = "1.1.0")] 15 pub trait MetadataExt { 16 /// Gain a reference to the underlying `stat` structure which contains 17 /// the raw information returned by the OS. 18 /// 19 /// The contents of the returned `stat` are **not** consistent across 20 /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the 21 /// cross-Unix abstractions contained within the raw stat. 22 #[stable(feature = "metadata_ext", since = "1.1.0")] 23 #[deprecated( 24 since = "1.8.0", 25 note = "deprecated in favor of the accessor \ 26 methods of this trait" 27 )] 28 #[allow(deprecated)] as_raw_stat(&self) -> &raw::stat29 fn as_raw_stat(&self) -> &raw::stat; 30 31 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_dev(&self) -> u6432 fn st_dev(&self) -> u64; 33 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_ino(&self) -> u6434 fn st_ino(&self) -> u64; 35 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_mode(&self) -> u3236 fn st_mode(&self) -> u32; 37 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_nlink(&self) -> u6438 fn st_nlink(&self) -> u64; 39 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_uid(&self) -> u3240 fn st_uid(&self) -> u32; 41 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_gid(&self) -> u3242 fn st_gid(&self) -> u32; 43 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_rdev(&self) -> u6444 fn st_rdev(&self) -> u64; 45 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_size(&self) -> u6446 fn st_size(&self) -> u64; 47 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_atime(&self) -> i6448 fn st_atime(&self) -> i64; 49 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_atime_nsec(&self) -> i6450 fn st_atime_nsec(&self) -> i64; 51 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_mtime(&self) -> i6452 fn st_mtime(&self) -> i64; 53 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_mtime_nsec(&self) -> i6454 fn st_mtime_nsec(&self) -> i64; 55 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_ctime(&self) -> i6456 fn st_ctime(&self) -> i64; 57 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_ctime_nsec(&self) -> i6458 fn st_ctime_nsec(&self) -> i64; 59 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_birthtime(&self) -> i6460 fn st_birthtime(&self) -> i64; 61 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_birthtime_nsec(&self) -> i6462 fn st_birthtime_nsec(&self) -> i64; 63 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_blksize(&self) -> u6464 fn st_blksize(&self) -> u64; 65 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_blocks(&self) -> u6466 fn st_blocks(&self) -> u64; 67 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_flags(&self) -> u3268 fn st_flags(&self) -> u32; 69 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_gen(&self) -> u3270 fn st_gen(&self) -> u32; 71 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_lspare(&self) -> u3272 fn st_lspare(&self) -> u32; 73 #[stable(feature = "metadata_ext2", since = "1.8.0")] st_qspare(&self) -> [u64; 2]74 fn st_qspare(&self) -> [u64; 2]; 75 } 76 77 #[stable(feature = "metadata_ext", since = "1.1.0")] 78 impl MetadataExt for Metadata { 79 #[allow(deprecated)] as_raw_stat(&self) -> &raw::stat80 fn as_raw_stat(&self) -> &raw::stat { 81 unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) } 82 } st_dev(&self) -> u6483 fn st_dev(&self) -> u64 { 84 self.as_inner().as_inner().st_dev as u64 85 } st_ino(&self) -> u6486 fn st_ino(&self) -> u64 { 87 self.as_inner().as_inner().st_ino as u64 88 } st_mode(&self) -> u3289 fn st_mode(&self) -> u32 { 90 self.as_inner().as_inner().st_mode as u32 91 } st_nlink(&self) -> u6492 fn st_nlink(&self) -> u64 { 93 self.as_inner().as_inner().st_nlink as u64 94 } st_uid(&self) -> u3295 fn st_uid(&self) -> u32 { 96 self.as_inner().as_inner().st_uid as u32 97 } st_gid(&self) -> u3298 fn st_gid(&self) -> u32 { 99 self.as_inner().as_inner().st_gid as u32 100 } st_rdev(&self) -> u64101 fn st_rdev(&self) -> u64 { 102 self.as_inner().as_inner().st_rdev as u64 103 } st_size(&self) -> u64104 fn st_size(&self) -> u64 { 105 self.as_inner().as_inner().st_size as u64 106 } st_atime(&self) -> i64107 fn st_atime(&self) -> i64 { 108 self.as_inner().as_inner().st_atime as i64 109 } st_atime_nsec(&self) -> i64110 fn st_atime_nsec(&self) -> i64 { 111 self.as_inner().as_inner().st_atime_nsec as i64 112 } st_mtime(&self) -> i64113 fn st_mtime(&self) -> i64 { 114 self.as_inner().as_inner().st_mtime as i64 115 } st_mtime_nsec(&self) -> i64116 fn st_mtime_nsec(&self) -> i64 { 117 self.as_inner().as_inner().st_mtime_nsec as i64 118 } st_ctime(&self) -> i64119 fn st_ctime(&self) -> i64 { 120 self.as_inner().as_inner().st_ctime as i64 121 } st_ctime_nsec(&self) -> i64122 fn st_ctime_nsec(&self) -> i64 { 123 self.as_inner().as_inner().st_ctime_nsec as i64 124 } st_birthtime(&self) -> i64125 fn st_birthtime(&self) -> i64 { 126 self.as_inner().as_inner().st_birthtime as i64 127 } st_birthtime_nsec(&self) -> i64128 fn st_birthtime_nsec(&self) -> i64 { 129 self.as_inner().as_inner().st_birthtime_nsec as i64 130 } st_blksize(&self) -> u64131 fn st_blksize(&self) -> u64 { 132 self.as_inner().as_inner().st_blksize as u64 133 } st_blocks(&self) -> u64134 fn st_blocks(&self) -> u64 { 135 self.as_inner().as_inner().st_blocks as u64 136 } st_gen(&self) -> u32137 fn st_gen(&self) -> u32 { 138 self.as_inner().as_inner().st_gen as u32 139 } st_flags(&self) -> u32140 fn st_flags(&self) -> u32 { 141 self.as_inner().as_inner().st_flags as u32 142 } st_lspare(&self) -> u32143 fn st_lspare(&self) -> u32 { 144 self.as_inner().as_inner().st_lspare as u32 145 } st_qspare(&self) -> [u64; 2]146 fn st_qspare(&self) -> [u64; 2] { 147 let qspare = self.as_inner().as_inner().st_qspare; 148 [qspare[0] as u64, qspare[1] as u64] 149 } 150 } 151 152 /// OS-specific extensions to [`fs::FileTimes`]. 153 #[unstable(feature = "file_set_times", issue = "98245")] 154 pub trait FileTimesExt: Sealed { 155 /// Set the creation time of a file. 156 #[unstable(feature = "file_set_times", issue = "98245")] set_created(self, t: SystemTime) -> Self157 fn set_created(self, t: SystemTime) -> Self; 158 } 159 160 #[unstable(feature = "file_set_times", issue = "98245")] 161 impl FileTimesExt for fs::FileTimes { set_created(mut self, t: SystemTime) -> Self162 fn set_created(mut self, t: SystemTime) -> Self { 163 self.as_inner_mut().set_created(t.into_inner()); 164 self 165 } 166 } 167