* 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
* }
* # 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 {
* # 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())
* ```
/// `puppies.jpg` and `hamsters.gif`:
///
/// ```rust
+/// use extra::glob::glob;
+///
/// for path in glob("/media/pictures/*.jpg") {
-/// println(path.to_str());
+/// println!("{}", path.display());
/// }
/// ```
///
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 {
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;
* # 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"));
*
* This function always returns this value:
*
- * ```rust
+ * ```rust,notest
* MatchOptions {
* case_sensitive: true,
* require_literal_separator: false.
* # Example
*
* ```rust
- * extern mod extra;
* use extra::hex::ToHex;
*
* fn main () {
* 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);
//! # Example
//!
//! ```rust
+//! use extra::lru_cache::LruCache;
+//!
//! let mut cache: LruCache<int, int> = LruCache::new(2);
//! cache.put(1, 10);
//! cache.put(2, 20);
* # 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 ...
* })
* })
* ```
/// # Example
///
/// ```rust
+/// use extra::url::{Url, UserInfo};
+///
/// let url = Url { scheme: ~"https",
/// user: Some(UserInfo { user: ~"username", pass: None }),
/// host: ~"example.com",
* # 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 {