Skip to content

Commit 52c50ba

Browse files
Add doc examples for std::fs::Metadata
1 parent f5d7952 commit 52c50ba

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/libstd/fs.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,23 @@ impl Metadata {
694694
///
695695
/// This field may not be available on all platforms, and will return an
696696
/// `Err` on platforms where it is not available.
697+
///
698+
/// # Examples
699+
///
700+
/// ```
701+
/// # fn foo() -> std::io::Result<()> {
702+
/// use std::fs;
703+
///
704+
/// let metadata = try!(fs::metadata("foo.txt"));
705+
///
706+
/// if let Ok(time) = metadata.modified() {
707+
/// println!("{:?}", time);
708+
/// } else {
709+
/// println!("Not supported on this platform");
710+
/// }
711+
/// # Ok(())
712+
/// # }
713+
/// ```
697714
#[stable(feature = "fs_time", since = "1.10.0")]
698715
pub fn modified(&self) -> io::Result<SystemTime> {
699716
self.0.modified().map(FromInner::from_inner)
@@ -712,6 +729,23 @@ impl Metadata {
712729
///
713730
/// This field may not be available on all platforms, and will return an
714731
/// `Err` on platforms where it is not available.
732+
///
733+
/// # Examples
734+
///
735+
/// ```
736+
/// # fn foo() -> std::io::Result<()> {
737+
/// use std::fs;
738+
///
739+
/// let metadata = try!(fs::metadata("foo.txt"));
740+
///
741+
/// if let Ok(time) = metadata.accessed() {
742+
/// println!("{:?}", time);
743+
/// } else {
744+
/// println!("Not supported on this platform");
745+
/// }
746+
/// # Ok(())
747+
/// # }
748+
/// ```
715749
#[stable(feature = "fs_time", since = "1.10.0")]
716750
pub fn accessed(&self) -> io::Result<SystemTime> {
717751
self.0.accessed().map(FromInner::from_inner)
@@ -726,6 +760,23 @@ impl Metadata {
726760
///
727761
/// This field may not be available on all platforms, and will return an
728762
/// `Err` on platforms where it is not available.
763+
///
764+
/// # Examples
765+
///
766+
/// ```
767+
/// # fn foo() -> std::io::Result<()> {
768+
/// use std::fs;
769+
///
770+
/// let metadata = try!(fs::metadata("foo.txt"));
771+
///
772+
/// if let Ok(time) = metadata.created() {
773+
/// println!("{:?}", time);
774+
/// } else {
775+
/// println!("Not supported on this platform");
776+
/// }
777+
/// # Ok(())
778+
/// # }
779+
/// ```
729780
#[stable(feature = "fs_time", since = "1.10.0")]
730781
pub fn created(&self) -> io::Result<SystemTime> {
731782
self.0.created().map(FromInner::from_inner)

0 commit comments

Comments
 (0)