Skip to content

Commit d882b1d

Browse files
committed
extra: Fix all code examples
1 parent 9f1739a commit d882b1d

File tree

7 files changed

+58
-39
lines changed

7 files changed

+58
-39
lines changed

src/libextra/arc.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
* With simple pipes, without Arc, a copy would have to be made for each task.
1919
*
2020
* ```rust
21-
* extern mod std;
22-
* use extra::arc;
23-
* let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
24-
* let shared_numbers=arc::Arc::new(numbers);
21+
* use extra::arc::Arc;
22+
* use std::{rand, vec};
2523
*
26-
* do 10.times {
27-
* let (port, chan) = stream();
24+
* let numbers = vec::from_fn(100, |i| (i as f32) * rand::random());
25+
* let shared_numbers = Arc::new(numbers);
26+
*
27+
* for _ in range(0, 10) {
28+
* let (port, chan) = Chan::new();
2829
* chan.send(shared_numbers.clone());
2930
*
3031
* do spawn {
31-
* let shared_numbers=port.recv();
32-
* let local_numbers=shared_numbers.get();
32+
* let shared_numbers = port.recv();
33+
* let local_numbers = shared_numbers.get();
3334
*
3435
* // Work with the local numbers
3536
* }
@@ -448,15 +449,18 @@ impl<T:Freeze + Send> RWArc<T> {
448449
* # Example
449450
*
450451
* ```rust
451-
* do arc.write_downgrade |mut write_token| {
452-
* do write_token.write_cond |state, condvar| {
453-
* ... exclusive access with mutable state ...
454-
* }
452+
* use extra::arc::RWArc;
453+
*
454+
* let arc = RWArc::new(1);
455+
* arc.write_downgrade(|mut write_token| {
456+
* write_token.write_cond(|state, condvar| {
457+
* // ... exclusive access with mutable state ...
458+
* });
455459
* let read_token = arc.downgrade(write_token);
456-
* do read_token.read |state| {
457-
* ... shared access with immutable state ...
458-
* }
459-
* }
460+
* read_token.read(|state| {
461+
* // ... shared access with immutable state ...
462+
* });
463+
* })
460464
* ```
461465
*/
462466
pub fn write_downgrade<U>(&self, blk: |v: RWWriteMode<T>| -> U) -> U {

src/libextra/future.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
* # Example
1616
*
1717
* ```rust
18+
* use extra::future::Future;
1819
* # fn fib(n: uint) -> uint {42};
1920
* # fn make_a_sandwich() {};
20-
* let mut delayed_fib = extra::future::spawn (|| fib(5000) );
21+
* let mut delayed_fib = do Future::spawn { fib(5000) };
2122
* make_a_sandwich();
2223
* println!("fib(5000) = {}", delayed_fib.get())
2324
* ```

src/libextra/glob.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ pub struct GlobIterator {
5353
/// `puppies.jpg` and `hamsters.gif`:
5454
///
5555
/// ```rust
56+
/// use extra::glob::glob;
57+
///
5658
/// for path in glob("/media/pictures/*.jpg") {
57-
/// println(path.to_str());
59+
/// println!("{}", path.display());
5860
/// }
5961
/// ```
6062
///
@@ -188,21 +190,23 @@ enum MatchResult {
188190
impl Pattern {
189191

190192
/**
191-
* This function compiles Unix shell style patterns: `?` matches any single character,
192-
* `*` matches any (possibly empty) sequence of characters and `[...]` matches any character
193-
* inside the brackets, unless the first character is `!` in which case it matches any
194-
* character except those between the `!` and the `]`. Character sequences can also specify
195-
* ranges of characters, as ordered by Unicode, so e.g. `[0-9]` specifies any character
196-
* between 0 and 9 inclusive.
193+
* This function compiles Unix shell style patterns: `?` matches any single
194+
* character, `*` matches any (possibly empty) sequence of characters and
195+
* `[...]` matches any character inside the brackets, unless the first
196+
* character is `!` in which case it matches any character except those
197+
* between the `!` and the `]`. Character sequences can also specify ranges
198+
* of characters, as ordered by Unicode, so e.g. `[0-9]` specifies any
199+
* character between 0 and 9 inclusive.
197200
*
198-
* The metacharacters `?`, `*`, `[`, `]` can be matched by using brackets (e.g. `[?]`).
199-
* When a `]` occurs immediately following `[` or `[!` then it is interpreted as
200-
* being part of, rather then ending, the character set, so `]` and NOT `]` can be
201-
* matched by `[]]` and `[!]]` respectively. The `-` character can be specified inside a
202-
* character sequence pattern by placing it at the start or the end, e.g. `[abc-]`.
201+
* The metacharacters `?`, `*`, `[`, `]` can be matched by using brackets
202+
* (e.g. `[?]`). When a `]` occurs immediately following `[` or `[!` then
203+
* it is interpreted as being part of, rather then ending, the character
204+
* set, so `]` and NOT `]` can be matched by `[]]` and `[!]]` respectively.
205+
* The `-` character can be specified inside a character sequence pattern by
206+
* placing it at the start or the end, e.g. `[abc-]`.
203207
*
204-
* When a `[` does not have a closing `]` before the end of the string then the `[` will
205-
* be treated literally.
208+
* When a `[` does not have a closing `]` before the end of the string then
209+
* the `[` will be treated literally.
206210
*/
207211
pub fn new(pattern: &str) -> Pattern {
208212

@@ -229,7 +233,8 @@ impl Pattern {
229233
match chars.slice_from(i + 3).position_elem(&']') {
230234
None => (),
231235
Some(j) => {
232-
let cs = parse_char_specifiers(chars.slice(i + 2, i + 3 + j));
236+
let chars = chars.slice(i + 2, i + 3 + j);
237+
let cs = parse_char_specifiers(chars);
233238
tokens.push(AnyExcept(cs));
234239
i += j + 4;
235240
continue;
@@ -292,6 +297,8 @@ impl Pattern {
292297
* # Example
293298
*
294299
* ```rust
300+
* use extra::glob::Pattern;
301+
*
295302
* assert!(Pattern::new("c?t").matches("cat"));
296303
* assert!(Pattern::new("k[!e]tteh").matches("kitteh"));
297304
* assert!(Pattern::new("d*g").matches("doog"));
@@ -509,7 +516,7 @@ impl MatchOptions {
509516
*
510517
* This function always returns this value:
511518
*
512-
* ```rust
519+
* ```rust,notest
513520
* MatchOptions {
514521
* case_sensitive: true,
515522
* require_literal_separator: false.

src/libextra/hex.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ impl<'a> ToHex for &'a [u8] {
2828
* # Example
2929
*
3030
* ```rust
31-
* extern mod extra;
3231
* use extra::hex::ToHex;
3332
*
3433
* fn main () {
@@ -71,12 +70,11 @@ impl<'a> FromHex for &'a str {
7170
* This converts a string literal to hexadecimal and back.
7271
*
7372
* ```rust
74-
* extern mod extra;
7573
* use extra::hex::{FromHex, ToHex};
7674
* use std::str;
7775
*
7876
* fn main () {
79-
* let hello_str = "Hello, World".to_hex();
77+
* let hello_str = "Hello, World".as_bytes().to_hex();
8078
* println!("{}", hello_str);
8179
* let bytes = hello_str.from_hex().unwrap();
8280
* println!("{:?}", bytes);

src/libextra/lru_cache.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//! # Example
1818
//!
1919
//! ```rust
20+
//! use extra::lru_cache::LruCache;
21+
//!
2022
//! let mut cache: LruCache<int, int> = LruCache::new(2);
2123
//! cache.put(1, 10);
2224
//! cache.put(2, 20);

src/libextra/sync.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,16 @@ impl RWLock {
568568
* # Example
569569
*
570570
* ```rust
571+
* use extra::sync::RWLock;
572+
*
573+
* let lock = RWLock::new();
571574
* lock.write_downgrade(|mut write_token| {
572575
* write_token.write_cond(|condvar| {
573-
* ... exclusive access ...
576+
* // ... exclusive access ...
574577
* });
575578
* let read_token = lock.downgrade(write_token);
576579
* read_token.read(|| {
577-
* ... shared access ...
580+
* // ... shared access ...
578581
* })
579582
* })
580583
* ```

src/libextra/url.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use std::uint;
2626
/// # Example
2727
///
2828
/// ```rust
29+
/// use extra::url::{Url, UserInfo};
30+
///
2931
/// let url = Url { scheme: ~"https",
3032
/// user: Some(UserInfo { user: ~"username", pass: None }),
3133
/// host: ~"example.com",
@@ -388,8 +390,10 @@ fn query_from_str(rawquery: &str) -> Query {
388390
* # Example
389391
*
390392
* ```rust
393+
* use extra::url;
394+
*
391395
* let query = ~[(~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")];
392-
* println(query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
396+
* println(url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
393397
* ```
394398
*/
395399
pub fn query_to_str(query: &Query) -> ~str {

0 commit comments

Comments
 (0)