@@ -114,6 +114,11 @@ pub struct Metadata(fs_imp::FileAttr);
114
114
/// information like the entry's path and possibly other metadata can be
115
115
/// learned.
116
116
///
117
+ /// #### Note: Iteration Order is Implementation-Defined
118
+ ///
119
+ /// The order in which this iterator returns entries is platform and filesystem
120
+ /// dependent.
121
+ ///
117
122
/// # Errors
118
123
///
119
124
/// This [`io::Result`] will be an [`Err`] if there's some sort of intermittent
@@ -1959,6 +1964,11 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
1959
1964
///
1960
1965
/// [changes]: ../io/index.html#platform-specific-behavior
1961
1966
///
1967
+ /// #### Note: Iteration Order is Implementation-Defined
1968
+ ///
1969
+ /// The order in which this iterator returns entries is platform and filesystem
1970
+ /// dependent.
1971
+ ///
1962
1972
/// # Errors
1963
1973
///
1964
1974
/// This function will return an error in the following situations, but is not
@@ -1991,6 +2001,28 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
1991
2001
/// Ok(())
1992
2002
/// }
1993
2003
/// ```
2004
+ ///
2005
+ /// ```rust,no_run
2006
+ /// use std::{fs, io};
2007
+ ///
2008
+ /// fn main() -> io::Result<()> {
2009
+ /// // The order read_dir returns entries is not guaranteed. If reproducible
2010
+ /// // ordering is required the entries should be explicitly sorted.
2011
+ /// let mut entries = fs::read_dir(".")?
2012
+ /// .map(|res| res.map(|e| e.path()))
2013
+ /// .collect::<Result<Vec<_>, io::Error>>()?;
2014
+ ///
2015
+ /// println!(
2016
+ /// "Entries before sorting (may or may not be sorted already): {:?}",
2017
+ /// entries
2018
+ /// );
2019
+ ///
2020
+ /// entries.sort();
2021
+ ///
2022
+ /// println!("Entries after sorting: {:?}", entries);
2023
+ /// Ok(())
2024
+ /// }
2025
+ /// ```
1994
2026
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1995
2027
pub fn read_dir < P : AsRef < Path > > ( path : P ) -> io:: Result < ReadDir > {
1996
2028
fs_imp:: readdir ( path. as_ref ( ) ) . map ( ReadDir )
0 commit comments