]> git.lizzy.rs Git - rust.git/commitdiff
extra: Fix all code examples
authorAlex Crichton <alex@alexcrichton.com>
Sun, 22 Dec 2013 21:31:37 +0000 (13:31 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 23 Dec 2013 17:10:36 +0000 (09:10 -0800)
src/libextra/arc.rs
src/libextra/future.rs
src/libextra/glob.rs
src/libextra/hex.rs
src/libextra/lru_cache.rs
src/libextra/sync.rs
src/libextra/url.rs

index 5a2b74e802116f0f0b461d85f1f7939a66df2f17..c1763c37bb5a16e029224cf4f7e839134707c6d4 100644 (file)
  * With simple pipes, without Arc, a copy would have to be made for each task.
  *
  * ```rust
- * extern mod std;
- * use extra::arc;
- * let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
- * let shared_numbers=arc::Arc::new(numbers);
+ * use extra::arc::Arc;
+ * use std::{rand, vec};
  *
- *   do 10.times {
- *       let (port, chan)  = stream();
+ * let numbers = vec::from_fn(100, |i| (i as f32) * rand::random());
+ * let shared_numbers = Arc::new(numbers);
+ *
+ *   for _ in range(0, 10) {
+ *       let (port, chan) = Chan::new();
  *       chan.send(shared_numbers.clone());
  *
  *       do spawn {
- *           let shared_numbers=port.recv();
- *           let local_numbers=shared_numbers.get();
+ *           let shared_numbers = port.recv();
+ *           let local_numbers = shared_numbers.get();
  *
  *           // Work with the local numbers
  *       }
@@ -448,15 +449,18 @@ pub fn read<U>(&self, blk: |x: &T| -> U) -> U {
      * # Example
      *
      * ```rust
-     * do arc.write_downgrade |mut write_token| {
-     *     do write_token.write_cond |state, condvar| {
-     *         ... exclusive access with mutable state ...
-     *     }
+     * use extra::arc::RWArc;
+     *
+     * let arc = RWArc::new(1);
+     * arc.write_downgrade(|mut write_token| {
+     *     write_token.write_cond(|state, condvar| {
+     *         // ... exclusive access with mutable state ...
+     *     });
      *     let read_token = arc.downgrade(write_token);
-     *     do read_token.read |state| {
-     *         ... shared access with immutable state ...
-     *     }
-     * }
+     *     read_token.read(|state| {
+     *         // ... shared access with immutable state ...
+     *     });
+     * })
      * ```
      */
     pub fn write_downgrade<U>(&self, blk: |v: RWWriteMode<T>| -> U) -> U {
index eb61b7781f1ba329228be28760065610227a6a1b..cb82c1abe1ebc0bb1852aba1770b6e49d54a1090 100644 (file)
  * # Example
  *
  * ```rust
+ * use extra::future::Future;
  * # fn fib(n: uint) -> uint {42};
  * # fn make_a_sandwich() {};
- * let mut delayed_fib = extra::future::spawn (|| fib(5000) );
+ * let mut delayed_fib = do Future::spawn { fib(5000) };
  * make_a_sandwich();
  * println!("fib(5000) = {}", delayed_fib.get())
  * ```
index 1182d526fa4532fda20847baac00ff3a15703032..bf75fa98b06c9d8b76279131cccecd8b8e6c869f 100644 (file)
@@ -53,8 +53,10 @@ pub struct GlobIterator {
 /// `puppies.jpg` and `hamsters.gif`:
 ///
 /// ```rust
+/// use extra::glob::glob;
+///
 /// for path in glob("/media/pictures/*.jpg") {
-///     println(path.to_str());
+///     println!("{}", path.display());
 /// }
 /// ```
 ///
@@ -188,21 +190,23 @@ enum MatchResult {
 impl Pattern {
 
     /**
-     * This function compiles Unix shell style patterns: `?` matches any single character,
-     * `*` matches any (possibly empty) sequence of characters and `[...]` matches any character
-     * inside the brackets, unless the first character is `!` in which case it matches any
-     * character except those between the `!` and the `]`. Character sequences can also specify
-     * ranges of characters, as ordered by Unicode, so e.g. `[0-9]` specifies any character
-     * between 0 and 9 inclusive.
+     * This function compiles Unix shell style patterns: `?` matches any single
+     * character, `*` matches any (possibly empty) sequence of characters and
+     * `[...]` matches any character inside the brackets, unless the first
+     * character is `!` in which case it matches any character except those
+     * between the `!` and the `]`. Character sequences can also specify ranges
+     * of characters, as ordered by Unicode, so e.g. `[0-9]` specifies any
+     * character between 0 and 9 inclusive.
      *
-     * The metacharacters `?`, `*`, `[`, `]` can be matched by using brackets (e.g. `[?]`).
-     * When a `]` occurs immediately following `[` or `[!` then it is interpreted as
-     * being part of, rather then ending, the character set, so `]` and NOT `]` can be
-     * matched by `[]]` and `[!]]` respectively. The `-` character can be specified inside a
-     * character sequence pattern by placing it at the start or the end, e.g. `[abc-]`.
+     * The metacharacters `?`, `*`, `[`, `]` can be matched by using brackets
+     * (e.g. `[?]`).  When a `]` occurs immediately following `[` or `[!` then
+     * it is interpreted as being part of, rather then ending, the character
+     * set, so `]` and NOT `]` can be matched by `[]]` and `[!]]` respectively.
+     * The `-` character can be specified inside a character sequence pattern by
+     * placing it at the start or the end, e.g. `[abc-]`.
      *
-     * When a `[` does not have a closing `]` before the end of the string then the `[` will
-     * be treated literally.
+     * When a `[` does not have a closing `]` before the end of the string then
+     * the `[` will be treated literally.
      */
     pub fn new(pattern: &str) -> Pattern {
 
@@ -229,7 +233,8 @@ pub fn new(pattern: &str) -> Pattern {
                         match chars.slice_from(i + 3).position_elem(&']') {
                             None => (),
                             Some(j) => {
-                                let cs = parse_char_specifiers(chars.slice(i + 2, i + 3 + j));
+                                let chars = chars.slice(i + 2, i + 3 + j);
+                                let cs = parse_char_specifiers(chars);
                                 tokens.push(AnyExcept(cs));
                                 i += j + 4;
                                 continue;
@@ -292,6 +297,8 @@ pub fn escape(s: &str) -> ~str {
      * # Example
      *
      * ```rust
+     * use extra::glob::Pattern;
+     *
      * assert!(Pattern::new("c?t").matches("cat"));
      * assert!(Pattern::new("k[!e]tteh").matches("kitteh"));
      * assert!(Pattern::new("d*g").matches("doog"));
@@ -509,7 +516,7 @@ impl MatchOptions {
      *
      * This function always returns this value:
      *
-     * ```rust
+     * ```rust,notest
      * MatchOptions {
      *     case_sensitive: true,
      *     require_literal_separator: false.
index 83dcc412f57f8edc924500b708b2eeb795e954c5..380476dc4bca07695ee745917cb5cab29cd3eb15 100644 (file)
@@ -28,7 +28,6 @@ impl<'a> ToHex for &'a [u8] {
      * # Example
      *
      * ```rust
-     * extern mod extra;
      * use extra::hex::ToHex;
      *
      * fn main () {
@@ -71,12 +70,11 @@ impl<'a> FromHex for &'a str {
      * This converts a string literal to hexadecimal and back.
      *
      * ```rust
-     * extern mod extra;
      * use extra::hex::{FromHex, ToHex};
      * use std::str;
      *
      * fn main () {
-     *     let hello_str = "Hello, World".to_hex();
+     *     let hello_str = "Hello, World".as_bytes().to_hex();
      *     println!("{}", hello_str);
      *     let bytes = hello_str.from_hex().unwrap();
      *     println!("{:?}", bytes);
index ff8748e1946c1f118baa5bf85557a9eb49d17e71..e1cb54ae45296e1524e47855bc8c7c0a5c50feaf 100644 (file)
@@ -17,6 +17,8 @@
 //! # Example
 //!
 //! ```rust
+//! use extra::lru_cache::LruCache;
+//!
 //! let mut cache: LruCache<int, int> = LruCache::new(2);
 //! cache.put(1, 10);
 //! cache.put(2, 20);
index 1546e9ca59cf46e76b037a68590cd604282792ff..57a7f38696d6c09dacd98198d86de5e3fd0a55e5 100644 (file)
@@ -568,13 +568,16 @@ pub fn write_cond<U>(&self, blk: |c: &Condvar| -> U) -> U {
      * # Example
      *
      * ```rust
+     * use extra::sync::RWLock;
+     *
+     * let lock = RWLock::new();
      * lock.write_downgrade(|mut write_token| {
      *     write_token.write_cond(|condvar| {
-     *         ... exclusive access ...
+     *         // ... exclusive access ...
      *     });
      *     let read_token = lock.downgrade(write_token);
      *     read_token.read(|| {
-     *         ... shared access ...
+     *         // ... shared access ...
      *     })
      * })
      * ```
index 13b87b9730923835e2767fbf56ee49468a9d38bb..79886273a15413a17ab670cacfb113b9218640fb 100644 (file)
@@ -26,6 +26,8 @@
 /// # Example
 ///
 /// ```rust
+/// use extra::url::{Url, UserInfo};
+///
 /// let url = Url { scheme: ~"https",
 ///                 user: Some(UserInfo { user: ~"username", pass: None }),
 ///                 host: ~"example.com",
@@ -388,8 +390,10 @@ fn query_from_str(rawquery: &str) -> Query {
  * # Example
  *
  * ```rust
+ * use extra::url;
+ *
  * let query = ~[(~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")];
- * println(query_to_str(&query));  // title=The%20Village&north=52.91&west=4.10
+ * println(url::query_to_str(&query));  // title=The%20Village&north=52.91&west=4.10
  * ```
  */
 pub fn query_to_str(query: &Query) -> ~str {