+
+ /// Changes the timestamps of the underlying file.
+ ///
+ /// # Platform-specific behavior
+ ///
+ /// This function currently corresponds to the `futimens` function on Unix (falling back to
+ /// `futimes` on macOS before 10.13) and the `SetFileTime` function on Windows. Note that this
+ /// [may change in the future][changes].
+ ///
+ /// [changes]: io#platform-specific-behavior
+ ///
+ /// # Errors
+ ///
+ /// This function will return an error if the user lacks permission to change timestamps on the
+ /// underlying file. It may also return an error in other os-specific unspecified cases.
+ ///
+ /// This function may return an error if the operating system lacks support to change one or
+ /// more of the timestamps set in the `FileTimes` structure.
+ ///
+ /// # Examples
+ ///
+ /// ```no_run
+ /// #![feature(file_set_times)]
+ ///
+ /// fn main() -> std::io::Result<()> {
+ /// use std::fs::{self, File, FileTimes};
+ ///
+ /// let src = fs::metadata("src")?;
+ /// let dest = File::options().write(true).open("dest")?;
+ /// let times = FileTimes::new()
+ /// .set_accessed(src.accessed()?)
+ /// .set_modified(src.modified()?);
+ /// dest.set_times(times)?;
+ /// Ok(())
+ /// }
+ /// ```
+ #[unstable(feature = "file_set_times", issue = "98245")]
+ #[doc(alias = "futimens")]
+ #[doc(alias = "futimes")]
+ #[doc(alias = "SetFileTime")]
+ pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
+ self.inner.set_times(times.0)
+ }
+
+ /// Changes the modification time of the underlying file.
+ ///
+ /// This is an alias for `set_times(FileTimes::new().set_modified(time))`.
+ #[unstable(feature = "file_set_times", issue = "98245")]
+ #[inline]
+ pub fn set_modified(&self, time: SystemTime) -> io::Result<()> {
+ self.set_times(FileTimes::new().set_modified(time))
+ }