about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-14 00:31:30 +0000
committerbors <bors@rust-lang.org>2014-07-14 00:31:30 +0000
commit3d70f50b2ce2e04bb8db934721eeaddb80a7cc27 (patch)
treef698377c7e6d91799f01319ab8300624a7cc8dee /src/libstd
parenta35774b128df41e49ed3e56690e31dda998d5fdd (diff)
parent77c4b3d26dab7bd2c95cf34c844760af5f79790e (diff)
downloadrust-3d70f50b2ce2e04bb8db934721eeaddb80a7cc27.tar.gz
rust-3d70f50b2ce2e04bb8db934721eeaddb80a7cc27.zip
auto merge of #15649 : catharsis/rust/rust-libstd-examples, r=alexcrichton
This patch adds doc examples for the make_absolute, change_dir,
errors_string and args functions in the os module.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/os.rs52
1 files changed, 45 insertions, 7 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 1a5be089252..86577a9840d 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -837,13 +837,24 @@ pub fn tmpdir() -> Path {
     }
 }
 
-/**
- * Convert a relative path to an absolute path
- *
- * If the given path is relative, return it prepended with the current working
- * directory. If the given path is already an absolute path, return it
- * as is.
- */
+///
+/// Convert a relative path to an absolute path
+///
+/// If the given path is relative, return it prepended with the current working
+/// directory. If the given path is already an absolute path, return it
+/// as is.
+///
+/// # Example
+/// ```rust
+/// use std::os;
+/// use std::path::Path;
+///
+/// // Assume we're in a path like /home/someuser
+/// let rel_path = Path::new("..");
+/// let abs_path = os::make_absolute(&rel_path);
+/// println!("The absolute path is {}", abs_path.display());
+/// // Prints "The absolute path is /home"
+/// ```
 // NB: this is here rather than in path because it is a form of environment
 // querying; what it does depends on the process working directory, not just
 // the input paths.
@@ -859,6 +870,16 @@ pub fn make_absolute(p: &Path) -> Path {
 
 /// Changes the current working directory to the specified path, returning
 /// whether the change was completed successfully or not.
+///
+/// # Example
+/// ```rust
+/// use std::os;
+/// use std::path::Path;
+///
+/// let root = Path::new("/");
+/// assert!(os::change_dir(&root));
+/// println!("Succesfully changed working directory to {}!", root.display());
+/// ```
 pub fn change_dir(p: &Path) -> bool {
     return chdir(p);
 
@@ -930,6 +951,13 @@ pub fn errno() -> uint {
 }
 
 /// Return the string corresponding to an `errno()` value of `errnum`.
+/// # Example
+/// ```rust
+/// use std::os;
+///
+/// // Same as println!("{}", last_os_error());
+/// println!("{}", os::error_string(os::errno() as uint));
+/// ```
 pub fn error_string(errnum: uint) -> String {
     return strerror(errnum);
 
@@ -1217,6 +1245,16 @@ extern "system" {
 ///
 /// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD.
 /// See `str::from_utf8_lossy` for details.
+/// # Example
+///
+/// ```rust
+/// use std::os;
+///
+/// // Prints each argument on a separate line
+/// for argument in os::args().iter() {
+///     println!("{}", argument);
+/// }
+/// ```
 pub fn args() -> Vec<String> {
     real_args()
 }