@@ -837,13 +837,24 @@ pub fn tmpdir() -> Path {
837
837
}
838
838
}
839
839
840
- /**
841
- * Convert a relative path to an absolute path
842
- *
843
- * If the given path is relative, return it prepended with the current working
844
- * directory. If the given path is already an absolute path, return it
845
- * as is.
846
- */
840
+ ///
841
+ /// Convert a relative path to an absolute path
842
+ ///
843
+ /// If the given path is relative, return it prepended with the current working
844
+ /// directory. If the given path is already an absolute path, return it
845
+ /// as is.
846
+ ///
847
+ /// # Example
848
+ /// ```rust
849
+ /// use std::os;
850
+ /// use std::path::Path;
851
+ ///
852
+ /// // Assume we're in a path like /home/someuser
853
+ /// let rel_path = Path::new("..");
854
+ /// let abs_path = os::make_absolute(&rel_path);
855
+ /// println!("The absolute path is {}", abs_path.display());
856
+ /// // Prints "The absolute path is /home"
857
+ /// ```
847
858
// NB: this is here rather than in path because it is a form of environment
848
859
// querying; what it does depends on the process working directory, not just
849
860
// the input paths.
@@ -859,6 +870,16 @@ pub fn make_absolute(p: &Path) -> Path {
859
870
860
871
/// Changes the current working directory to the specified path, returning
861
872
/// whether the change was completed successfully or not.
873
+ ///
874
+ /// # Example
875
+ /// ```rust
876
+ /// use std::os;
877
+ /// use std::path::Path;
878
+ ///
879
+ /// let root = Path::new("/");
880
+ /// assert!(os::change_dir(&root));
881
+ /// println!("Succesfully changed working directory to {}!", root.display());
882
+ /// ```
862
883
pub fn change_dir ( p : & Path ) -> bool {
863
884
return chdir ( p) ;
864
885
@@ -930,6 +951,13 @@ pub fn errno() -> uint {
930
951
}
931
952
932
953
/// Return the string corresponding to an `errno()` value of `errnum`.
954
+ /// # Example
955
+ /// ```rust
956
+ /// use std::os;
957
+ ///
958
+ /// // Same as println!("{}", last_os_error());
959
+ /// println!("{}", os::error_string(os::errno() as uint));
960
+ /// ```
933
961
pub fn error_string ( errnum : uint ) -> String {
934
962
return strerror ( errnum) ;
935
963
@@ -1217,6 +1245,16 @@ extern "system" {
1217
1245
///
1218
1246
/// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD.
1219
1247
/// See `str::from_utf8_lossy` for details.
1248
+ /// # Example
1249
+ ///
1250
+ /// ```rust
1251
+ /// use std::os;
1252
+ ///
1253
+ /// // Prints each argument on a separate line
1254
+ /// for argument in os::args().iter() {
1255
+ /// println!("{}", argument);
1256
+ /// }
1257
+ /// ```
1220
1258
pub fn args ( ) -> Vec < String > {
1221
1259
real_args ( )
1222
1260
}
0 commit comments