extra: Fix all code examples
This commit is contained in:
parent
9f1739a8e1
commit
d882b1d4f9
@ -18,18 +18,19 @@
|
||||
* 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 @@ impl<T:Freeze + Send> RWArc<T> {
|
||||
* # 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 {
|
||||
|
@ -15,9 +15,10 @@
|
||||
* # 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())
|
||||
* ```
|
||||
|
@ -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 @@ impl 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 @@ impl Pattern {
|
||||
* # 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.
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -568,13 +568,16 @@ impl RWLock {
|
||||
* # 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 ...
|
||||
* })
|
||||
* })
|
||||
* ```
|
||||
|
@ -26,6 +26,8 @@ use std::uint;
|
||||
/// # 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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user