1
Fork 0

syntax highlight code examples in docstrings

This commit is contained in:
Daniel Micay 2013-05-27 09:49:54 -04:00
parent 3941f78a1b
commit 0d5fdce82e
17 changed files with 165 additions and 117 deletions

View file

@ -17,7 +17,7 @@
* In this example, a large vector of floats is shared between several tasks. * In this example, a large vector of floats is shared between several tasks.
* With simple pipes, without ARC, a copy would have to be made for each task. * With simple pipes, without ARC, a copy would have to be made for each task.
* *
* ~~~ * ~~~ {.rust}
* extern mod std; * extern mod std;
* use std::arc; * use std::arc;
* let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random()); * let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
@ -370,7 +370,10 @@ pub impl<T:Const + Owned> RWARC<T> {
* See sync::rwlock.write_downgrade(). The RWWriteMode token must be used * See sync::rwlock.write_downgrade(). The RWWriteMode token must be used
* to obtain the &mut T, and can be transformed into a RWReadMode token by * to obtain the &mut T, and can be transformed into a RWReadMode token by
* calling downgrade(), after which a &T can be obtained instead. * calling downgrade(), after which a &T can be obtained instead.
* ~~~ *
* # Example
*
* ~~~ {.rust}
* do arc.write_downgrade |write_mode| { * do arc.write_downgrade |write_mode| {
* do (&write_mode).write_cond |state, condvar| { * do (&write_mode).write_cond |state, condvar| {
* ... exclusive access with mutable state ... * ... exclusive access with mutable state ...

View file

@ -28,9 +28,9 @@ impl<'self> ToBase64 for &'self [u8] {
/** /**
* Turn a vector of `u8` bytes into a base64 string. * Turn a vector of `u8` bytes into a base64 string.
* *
* *Example*: * # Example
* *
* ~~~~ * ~~~ {.rust}
* extern mod std; * extern mod std;
* use std::base64::ToBase64; * use std::base64::ToBase64;
* *
@ -38,7 +38,7 @@ impl<'self> ToBase64 for &'self [u8] {
* let str = [52,32].to_base64(); * let str = [52,32].to_base64();
* println(fmt!("%s", str)); * println(fmt!("%s", str));
* } * }
* ~~~~ * ~~~
*/ */
fn to_base64(&self) -> ~str { fn to_base64(&self) -> ~str {
let mut s = ~""; let mut s = ~"";
@ -91,9 +91,9 @@ impl<'self> ToBase64 for &'self str {
* Convert any string (literal, `@`, `&`, or `~`) to base64 encoding. * Convert any string (literal, `@`, `&`, or `~`) to base64 encoding.
* *
* *
* *Example*: * # Example
* *
* ~~~~ * ~~~ {.rust}
* extern mod std; * extern mod std;
* use std::base64::ToBase64; * use std::base64::ToBase64;
* *
@ -101,7 +101,7 @@ impl<'self> ToBase64 for &'self str {
* let str = "Hello, World".to_base64(); * let str = "Hello, World".to_base64();
* println(fmt!("%s",str)); * println(fmt!("%s",str));
* } * }
* ~~~~ * ~~~
* *
*/ */
fn to_base64(&self) -> ~str { fn to_base64(&self) -> ~str {
@ -118,9 +118,9 @@ impl FromBase64 for ~[u8] {
* Convert base64 `u8` vector into u8 byte values. * Convert base64 `u8` vector into u8 byte values.
* Every 4 encoded characters is converted into 3 octets, modulo padding. * Every 4 encoded characters is converted into 3 octets, modulo padding.
* *
* *Example*: * # Example
* *
* ~~~~ * ~~~ {.rust}
* extern mod std; * extern mod std;
* use std::base64::ToBase64; * use std::base64::ToBase64;
* use std::base64::FromBase64; * use std::base64::FromBase64;
@ -131,7 +131,7 @@ impl FromBase64 for ~[u8] {
* let bytes = str.from_base64(); * let bytes = str.from_base64();
* println(fmt!("%?",bytes)); * println(fmt!("%?",bytes));
* } * }
* ~~~~ * ~~~
*/ */
fn from_base64(&self) -> ~[u8] { fn from_base64(&self) -> ~[u8] {
if self.len() % 4u != 0u { fail!("invalid base64 length"); } if self.len() % 4u != 0u { fail!("invalid base64 length"); }
@ -196,11 +196,11 @@ impl FromBase64 for ~str {
* You can use the `from_bytes` function in `core::str` * You can use the `from_bytes` function in `core::str`
* to turn a `[u8]` into a string with characters corresponding to those values. * to turn a `[u8]` into a string with characters corresponding to those values.
* *
* *Example*: * # Example
* *
* This converts a string literal to base64 and back. * This converts a string literal to base64 and back.
* *
* ~~~~ * ~~~ {.rust}
* extern mod std; * extern mod std;
* use std::base64::ToBase64; * use std::base64::ToBase64;
* use std::base64::FromBase64; * use std::base64::FromBase64;
@ -214,7 +214,7 @@ impl FromBase64 for ~str {
* let result_str = str::from_bytes(bytes); * let result_str = str::from_bytes(bytes);
* println(fmt!("%s",result_str)); * println(fmt!("%s",result_str));
* } * }
* ~~~~ * ~~~
*/ */
fn from_base64(&self) -> ~[u8] { fn from_base64(&self) -> ~[u8] {
str::to_bytes(*self).from_base64() str::to_bytes(*self).from_base64()

View file

@ -25,7 +25,7 @@ ports and channels.
This example sends boxed integers across tasks using serialization. This example sends boxed integers across tasks using serialization.
~~~ ~~~ {.rust}
let (port, chan) = serial::pipe_stream(); let (port, chan) = serial::pipe_stream();
do task::spawn || { do task::spawn || {

View file

@ -14,7 +14,7 @@
* *
* # Example * # Example
* *
* ~~~ * ~~~ {.rust}
* # fn fib(n: uint) -> uint {42}; * # fn fib(n: uint) -> uint {42};
* # fn make_a_sandwich() {}; * # fn make_a_sandwich() {};
* let mut delayed_fib = std::future::spawn (|| fib(5000) ); * let mut delayed_fib = std::future::spawn (|| fib(5000) );

View file

@ -466,7 +466,7 @@ fn read_future(sock: &TcpSocket, timeout_msecs: uint)
* Here, the `new_conn` is used in conjunction with `accept` from within * Here, the `new_conn` is used in conjunction with `accept` from within
* a task spawned by the `new_connect_cb` passed into `listen` * a task spawned by the `new_connect_cb` passed into `listen`
* *
* ~~~~~~~~~~~ * ~~~ {.rust}
* do net::tcp::listen(remote_ip, remote_port, backlog, iotask, * do net::tcp::listen(remote_ip, remote_port, backlog, iotask,
* // this callback is ran once after the connection is successfully * // this callback is ran once after the connection is successfully
* // set up * // set up
@ -497,7 +497,7 @@ fn read_future(sock: &TcpSocket, timeout_msecs: uint)
* None => () * None => ()
* } * }
* }; * };
* ~~~~~~~~~~~ * ~~~
* *
* # Arguments * # Arguments
* *

View file

@ -545,7 +545,10 @@ pub impl RWlock {
* the meantime (such as unlocking and then re-locking as a reader would * the meantime (such as unlocking and then re-locking as a reader would
* do). The block takes a "write mode token" argument, which can be * do). The block takes a "write mode token" argument, which can be
* transformed into a "read mode token" by calling downgrade(). Example: * transformed into a "read mode token" by calling downgrade(). Example:
* ~~~ *
* # Example
*
* ~~~ {.rust}
* do lock.write_downgrade |write_mode| { * do lock.write_downgrade |write_mode| {
* do (&write_mode).write_cond |condvar| { * do (&write_mode).write_cond |condvar| {
* ... exclusive access ... * ... exclusive access ...

View file

@ -43,10 +43,13 @@ use from_str::FromStr;
* Negation of a boolean value. * Negation of a boolean value.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::not(true) * rusti> std::bool::not(true)
* false * false
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::not(false) * rusti> std::bool::not(false)
* true * true
* ~~~ * ~~~
@ -57,10 +60,13 @@ pub fn not(v: bool) -> bool { !v }
* Conjunction of two boolean values. * Conjunction of two boolean values.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::and(true, false) * rusti> std::bool::and(true, false)
* false * false
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::and(true, true) * rusti> std::bool::and(true, true)
* true * true
* ~~~ * ~~~
@ -71,10 +77,13 @@ pub fn and(a: bool, b: bool) -> bool { a && b }
* Disjunction of two boolean values. * Disjunction of two boolean values.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::or(true, false) * rusti> std::bool::or(true, false)
* true * true
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::or(false, false) * rusti> std::bool::or(false, false)
* false * false
* ~~~ * ~~~
@ -87,10 +96,13 @@ pub fn or(a: bool, b: bool) -> bool { a || b }
* 'exclusive or' is identical to `or(and(a, not(b)), and(not(a), b))`. * 'exclusive or' is identical to `or(and(a, not(b)), and(not(a), b))`.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::xor(true, false) * rusti> std::bool::xor(true, false)
* true * true
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::xor(true, true) * rusti> std::bool::xor(true, true)
* false * false
* ~~~ * ~~~
@ -105,10 +117,12 @@ pub fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
* 'if a then b' is equivalent to `!a || b`. * 'if a then b' is equivalent to `!a || b`.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::implies(true, true) * rusti> std::bool::implies(true, true)
* true * true
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::implies(true, false) * rusti> std::bool::implies(true, false)
* false * false
* ~~~ * ~~~
@ -121,10 +135,13 @@ pub fn implies(a: bool, b: bool) -> bool { !a || b }
* Two booleans are equal if they have the same value. * Two booleans are equal if they have the same value.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::eq(false, true) * rusti> std::bool::eq(false, true)
* false * false
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::eq(false, false) * rusti> std::bool::eq(false, false)
* true * true
* ~~~ * ~~~
@ -137,10 +154,13 @@ pub fn eq(a: bool, b: bool) -> bool { a == b }
* Two booleans are not equal if they have different values. * Two booleans are not equal if they have different values.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::ne(false, true) * rusti> std::bool::ne(false, true)
* true * true
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::ne(false, false) * rusti> std::bool::ne(false, false)
* false * false
* ~~~ * ~~~
@ -151,10 +171,13 @@ pub fn ne(a: bool, b: bool) -> bool { a != b }
* Is a given boolean value true? * Is a given boolean value true?
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::is_true(true) * rusti> std::bool::is_true(true)
* true * true
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::is_true(false) * rusti> std::bool::is_true(false)
* false * false
* ~~~ * ~~~
@ -165,10 +188,13 @@ pub fn is_true(v: bool) -> bool { v }
* Is a given boolean value false? * Is a given boolean value false?
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::is_false(false) * rusti> std::bool::is_false(false)
* true * true
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::is_false(true) * rusti> std::bool::is_false(true)
* false * false
* ~~~ * ~~~
@ -181,13 +207,18 @@ pub fn is_false(v: bool) -> bool { !v }
* Yields an `Option<bool>`, because `str` may or may not actually be parseable. * Yields an `Option<bool>`, because `str` may or may not actually be parseable.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> FromStr::from_str::<bool>("true") * rusti> FromStr::from_str::<bool>("true")
* Some(true) * Some(true)
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> FromStr::from_str::<bool>("false") * rusti> FromStr::from_str::<bool>("false")
* Some(false) * Some(false)
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> FromStr::from_str::<bool>("not even a boolean") * rusti> FromStr::from_str::<bool>("not even a boolean")
* None * None
* ~~~ * ~~~
@ -206,10 +237,13 @@ impl FromStr for bool {
* Convert a `bool` to a `str`. * Convert a `bool` to a `str`.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::to_str(true) * rusti> std::bool::to_str(true)
* "true" * "true"
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::to_str(false) * rusti> std::bool::to_str(false)
* "false" * "false"
* ~~~ * ~~~
@ -237,10 +271,13 @@ pub fn all_values(blk: &fn(v: bool)) {
* Convert a `bool` to a `u8`. * Convert a `bool` to a `u8`.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* rusti> std::bool::to_bit(true) * rusti> std::bool::to_bit(true)
* 1 * 1
* ~~~ * ~~~
*
* ~~~ {.rust}
* rusti> std::bool::to_bit(false) * rusti> std::bool::to_bit(false)
* 0 * 0
* ~~~ * ~~~

View file

@ -1009,8 +1009,9 @@ pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> @Reader {
/** /**
* Gives a `Reader` that allows you to read values from standard input. * Gives a `Reader` that allows you to read values from standard input.
* *
* # Examples * # Example
* ~~~ *
* ~~~ {.rust}
* let stdin = core::io::stdin(); * let stdin = core::io::stdin();
* let line = stdin.read_line(); * let line = stdin.read_line();
* core::io::print(line); * core::io::print(line);
@ -1572,8 +1573,9 @@ pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
/** /**
* Gives a `Writer` which allows you to write to the standard output. * Gives a `Writer` which allows you to write to the standard output.
* *
* # Examples * # Example
* ~~~ *
* ~~~ {.rust}
* let stdout = core::io::stdout(); * let stdout = core::io::stdout();
* stdout.write_str("hello\n"); * stdout.write_str("hello\n");
* ~~~ * ~~~
@ -1583,8 +1585,9 @@ pub fn stdout() -> @Writer { fd_writer(libc::STDOUT_FILENO as c_int, false) }
/** /**
* Gives a `Writer` which allows you to write to standard error. * Gives a `Writer` which allows you to write to standard error.
* *
* # Examples * # Example
* ~~~ *
* ~~~ {.rust}
* let stderr = core::io::stderr(); * let stderr = core::io::stderr();
* stderr.write_str("hello\n"); * stderr.write_str("hello\n");
* ~~~ * ~~~
@ -1597,8 +1600,9 @@ pub fn stderr() -> @Writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
* This string will not have an implicit newline at the end. If you want * This string will not have an implicit newline at the end. If you want
* an implicit newline, please see `println`. * an implicit newline, please see `println`.
* *
* # Examples * # Example
* ~~~ *
* ~~~ {.rust}
* // print is imported into the prelude, and so is always available. * // print is imported into the prelude, and so is always available.
* print("hello"); * print("hello");
* ~~~ * ~~~
@ -1612,8 +1616,9 @@ pub fn print(s: &str) {
* *
* If you do not want an implicit newline, please see `print`. * If you do not want an implicit newline, please see `print`.
* *
* # Examples * # Example
* ~~~ *
* ~~~ {.rust}
* // println is imported into the prelude, and so is always available. * // println is imported into the prelude, and so is always available.
* println("hello"); * println("hello");
* ~~~ * ~~~

View file

@ -16,14 +16,14 @@ An internal iterator takes `fn(...) -> bool` as a parameter, with returning `fal
breaking out of iteration. The adaptors in the module work with any such iterator, not just ones breaking out of iteration. The adaptors in the module work with any such iterator, not just ones
tied to specific traits. For example: tied to specific traits. For example:
~~~~ ~~~ {.rust}
println(iter::to_vec(|f| uint::range(0, 20, f)).to_str()); println(iter::to_vec(|f| uint::range(0, 20, f)).to_str());
~~~~ ~~~
An external iterator object implementing the interface in the `iterator` module can be used as an An external iterator object implementing the interface in the `iterator` module can be used as an
internal iterator by calling the `advance` method. For example: internal iterator by calling the `advance` method. For example:
~~~~ ~~~ {.rust}
use core::iterator::*; use core::iterator::*;
let xs = [0u, 1, 2, 3, 4, 5]; let xs = [0u, 1, 2, 3, 4, 5];
@ -32,7 +32,7 @@ let mut it = xs.iter().chain(ys.iter());
for it.advance |&x: &uint| { for it.advance |&x: &uint| {
println(x.to_str()); println(x.to_str());
} }
~~~~ ~~~
Internal iterators provide a subset of the functionality of an external iterator. It's not possible Internal iterators provide a subset of the functionality of an external iterator. It's not possible
to interleave them to implement algorithms like `zip`, `union` and `merge`. However, they're often to interleave them to implement algorithms like `zip`, `union` and `merge`. However, they're often
@ -55,7 +55,7 @@ pub trait Times {
* *
* # Example: * # Example:
* *
* ~~~ * ~~~ {.rust}
* let xs = ~[1, 2, 3]; * let xs = ~[1, 2, 3];
* let ys = do iter::to_vec |f| { xs.each(|x| f(*x)) }; * let ys = do iter::to_vec |f| { xs.each(|x| f(*x)) };
* assert_eq!(xs, ys); * assert_eq!(xs, ys);
@ -73,11 +73,11 @@ pub fn to_vec<T>(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T] {
* *
* Example: * Example:
* *
* ~~~~ * ~~~ {.rust}
* let xs = ~[1u, 2, 3, 4, 5]; * let xs = ~[1u, 2, 3, 4, 5];
* assert!(any(|&x: &uint| x > 2, |f| xs.each(f))); * assert!(any(|&x: &uint| x > 2, |f| xs.each(f)));
* assert!(!any(|&x: &uint| x > 5, |f| xs.each(f))); * assert!(!any(|&x: &uint| x > 5, |f| xs.each(f)));
* ~~~~ * ~~~
*/ */
#[inline(always)] #[inline(always)]
pub fn any<T>(predicate: &fn(T) -> bool, pub fn any<T>(predicate: &fn(T) -> bool,
@ -95,10 +95,10 @@ pub fn any<T>(predicate: &fn(T) -> bool,
* *
* # Example: * # Example:
* *
* ~~~~ * ~~~ {.rust}
* assert!(all(|&x: &uint| x < 6, |f| uint::range(1, 6, f))); * assert!(all(|&x: &uint| x < 6, |f| uint::range(1, 6, f)));
* assert!(!all(|&x: &uint| x < 5, |f| uint::range(1, 6, f))); * assert!(!all(|&x: &uint| x < 5, |f| uint::range(1, 6, f)));
* ~~~~ * ~~~
*/ */
#[inline(always)] #[inline(always)]
pub fn all<T>(predicate: &fn(T) -> bool, pub fn all<T>(predicate: &fn(T) -> bool,
@ -113,10 +113,10 @@ pub fn all<T>(predicate: &fn(T) -> bool,
* *
* # Example: * # Example:
* *
* ~~~~ * ~~~ {.rust}
* let xs = ~[1u, 2, 3, 4, 5, 6]; * let xs = ~[1u, 2, 3, 4, 5, 6];
* assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.each(f)).unwrap(), 4); * assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.each(f)).unwrap(), 4);
* ~~~~ * ~~~
*/ */
#[inline(always)] #[inline(always)]
pub fn find<T>(predicate: &fn(&T) -> bool, pub fn find<T>(predicate: &fn(&T) -> bool,
@ -134,10 +134,10 @@ pub fn find<T>(predicate: &fn(&T) -> bool,
* *
* # Example: * # Example:
* *
* ~~~~ * ~~~ {.rust}
* let xs = ~[8, 2, 3, 1, -5, 9, 11, 15]; * let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
* assert_eq!(max(|f| xs.each(f)).unwrap(), &15); * assert_eq!(max(|f| xs.each(f)).unwrap(), &15);
* ~~~~ * ~~~
*/ */
#[inline] #[inline]
pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> { pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
@ -160,10 +160,10 @@ pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
* *
* # Example: * # Example:
* *
* ~~~~ * ~~~ {.rust}
* let xs = ~[8, 2, 3, 1, -5, 9, 11, 15]; * let xs = ~[8, 2, 3, 1, -5, 9, 11, 15];
* assert_eq!(max(|f| xs.each(f)).unwrap(), &-5); * assert_eq!(max(|f| xs.each(f)).unwrap(), &-5);
* ~~~~ * ~~~
*/ */
#[inline] #[inline]
pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> { pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
@ -186,9 +186,9 @@ pub fn min<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> {
* *
* # Example: * # Example:
* *
* ~~~~ * ~~~ {.rust}
* assert_eq!(fold(0i, |f| int::range(1, 5, f), |a, x| *a += x), 10); * assert_eq!(fold(0i, |f| int::range(1, 5, f), |a, x| *a += x), 10);
* ~~~~ * ~~~
*/ */
#[inline] #[inline]
pub fn fold<T, U>(start: T, iter: &fn(f: &fn(U) -> bool) -> bool, f: &fn(&mut T, U)) -> T { pub fn fold<T, U>(start: T, iter: &fn(f: &fn(U) -> bool) -> bool, f: &fn(&mut T, U)) -> T {
@ -207,11 +207,11 @@ pub fn fold<T, U>(start: T, iter: &fn(f: &fn(U) -> bool) -> bool, f: &fn(&mut T,
* *
* # Example: * # Example:
* *
* ~~~~ * ~~~ {.rust}
* fn product<T: One + Mul<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T { * fn product<T: One + Mul<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
* fold_ref(One::one::<T>(), iter, |a, x| *a = a.mul(x)) * fold_ref(One::one::<T>(), iter, |a, x| *a = a.mul(x))
* } * }
* ~~~~ * ~~~
*/ */
#[inline] #[inline]
pub fn fold_ref<T, U>(start: T, iter: &fn(f: &fn(&U) -> bool) -> bool, f: &fn(&mut T, &U)) -> T { pub fn fold_ref<T, U>(start: T, iter: &fn(f: &fn(&U) -> bool) -> bool, f: &fn(&mut T, &U)) -> T {
@ -227,10 +227,10 @@ pub fn fold_ref<T, U>(start: T, iter: &fn(f: &fn(&U) -> bool) -> bool, f: &fn(&m
* *
* # Example: * # Example:
* *
* ~~~~ * ~~~ {.rust}
* let xs: ~[int] = ~[1, 2, 3, 4]; * let xs: ~[int] = ~[1, 2, 3, 4];
* assert_eq!(do sum |f| { xs.each(f) }, 10); * assert_eq!(do sum |f| { xs.each(f) }, 10);
* ~~~~ * ~~~
*/ */
#[inline(always)] #[inline(always)]
pub fn sum<T: Zero + Add<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T { pub fn sum<T: Zero + Add<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
@ -242,10 +242,10 @@ pub fn sum<T: Zero + Add<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {
* *
* # Example: * # Example:
* *
* ~~~~ * ~~~ {.rust}
* let xs: ~[int] = ~[1, 2, 3, 4]; * let xs: ~[int] = ~[1, 2, 3, 4];
* assert_eq!(do product |f| { xs.each(f) }, 24); * assert_eq!(do product |f| { xs.each(f) }, 24);
* ~~~~ * ~~~
*/ */
#[inline(always)] #[inline(always)]
pub fn product<T: One + Mul<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T { pub fn product<T: One + Mul<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T {

View file

@ -364,7 +364,7 @@ impl Round for f32 {
/// ///
/// The fractional part of the number, satisfying: /// The fractional part of the number, satisfying:
/// ///
/// ~~~ /// ~~~ {.rust}
/// assert!(x == trunc(x) + fract(x)) /// assert!(x == trunc(x) + fract(x))
/// ~~~ /// ~~~
/// ///

View file

@ -376,7 +376,7 @@ impl Round for f64 {
/// ///
/// The fractional part of the number, satisfying: /// The fractional part of the number, satisfying:
/// ///
/// ~~~ /// ~~~ {.rust}
/// assert!(x == trunc(x) + fract(x)) /// assert!(x == trunc(x) + fract(x))
/// ~~~ /// ~~~
/// ///

View file

@ -454,7 +454,7 @@ impl Round for float {
/// ///
/// The fractional part of the number, satisfying: /// The fractional part of the number, satisfying:
/// ///
/// ~~~ /// ~~~ {.rust}
/// assert!(x == trunc(x) + fract(x)) /// assert!(x == trunc(x) + fract(x))
/// ~~~ /// ~~~
/// ///

View file

@ -16,7 +16,7 @@ the other can receive messages. The set of legal messages and which
directions they can flow at any given point are determined by a directions they can flow at any given point are determined by a
protocol. Below is an example protocol. protocol. Below is an example protocol.
~~~ ~~~ {.rust}
proto! pingpong ( proto! pingpong (
ping: send { ping: send {
ping -> pong ping -> pong
@ -785,7 +785,7 @@ or `right` if the second endpoint receives something. In each case,
the result includes the other endpoint as well so it can be used the result includes the other endpoint as well so it can be used
again. Below is an example of using `select2`. again. Below is an example of using `select2`.
~~~ ~~~ {.rust}
match select2(a, b) { match select2(a, b) {
left((none, b)) { left((none, b)) {
// endpoint a was closed. // endpoint a was closed.

View file

@ -20,7 +20,8 @@ See the `distributions` submodule for sampling random numbers from
distributions like normal and exponential. distributions like normal and exponential.
# Examples # Examples
~~~
~~~ {.rust}
use core::rand::RngUtil; use core::rand::RngUtil;
fn main() { fn main() {
@ -31,7 +32,7 @@ fn main() {
} }
~~~ ~~~
~~~ ~~~ {.rust}
fn main () { fn main () {
let tuple_ptr = rand::random::<~(f64, char)>(); let tuple_ptr = rand::random::<~(f64, char)>();
println(fmt!("%?", tuple_ptr)) println(fmt!("%?", tuple_ptr))
@ -276,9 +277,9 @@ pub trait RngUtil {
/** /**
* Return a bool with a 1 in n chance of true * Return a bool with a 1 in n chance of true
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *
@ -292,9 +293,9 @@ pub trait RngUtil {
/** /**
* Return a random string of the specified length composed of A-Z,a-z,0-9 * Return a random string of the specified length composed of A-Z,a-z,0-9
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *
@ -308,9 +309,9 @@ pub trait RngUtil {
/** /**
* Return a random byte string of the specified length * Return a random byte string of the specified length
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *
@ -324,9 +325,9 @@ pub trait RngUtil {
/** /**
* Choose an item randomly, failing if values is empty * Choose an item randomly, failing if values is empty
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *
@ -343,9 +344,9 @@ pub trait RngUtil {
* Choose an item respecting the relative weights, failing if the sum of * Choose an item respecting the relative weights, failing if the sum of
* the weights is 0 * the weights is 0
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *
@ -363,9 +364,9 @@ pub trait RngUtil {
* Choose Some(item) respecting the relative weights, returning none if * Choose Some(item) respecting the relative weights, returning none if
* the sum of the weights is 0 * the sum of the weights is 0
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *
@ -384,9 +385,9 @@ pub trait RngUtil {
* Return a vec containing copies of the items, in order, where * Return a vec containing copies of the items, in order, where
* the weight of the item determines how many copies there are * the weight of the item determines how many copies there are
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *
@ -403,9 +404,9 @@ pub trait RngUtil {
/** /**
* Shuffle a vec * Shuffle a vec
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *
@ -419,9 +420,9 @@ pub trait RngUtil {
/** /**
* Shuffle a mutable vec in place * Shuffle a mutable vec in place
* *
* *Example* * # Example
* *
* ~~~ * ~~~ {.rust}
* *
* use core::rand::RngUtil; * use core::rand::RngUtil;
* *

View file

@ -726,7 +726,7 @@ fn iter_between_matches<'a,'b>(s: &'a str,
* *
* # Example * # Example
* *
* ~~~ * ~~~ {.rust}
* let mut v = ~[]; * let mut v = ~[];
* for each_split_str(".XXX.YYY.", ".") |subs| { v.push(subs); } * for each_split_str(".XXX.YYY.", ".") |subs| { v.push(subs); }
* assert!(v == ["", "XXX", "YYY", ""]); * assert!(v == ["", "XXX", "YYY", ""]);
@ -1923,7 +1923,7 @@ pub fn is_char_boundary(s: &str, index: uint) -> bool {
* *
* # Example * # Example
* *
* ~~~ * ~~~ {.rust}
* let s = "中华Việt Nam"; * let s = "中华Việt Nam";
* let i = 0u; * let i = 0u;
* while i < str::len(s) { * while i < str::len(s) {
@ -2109,7 +2109,7 @@ static tag_six_b: uint = 252u;
* *
* # Example * # Example
* *
* ~~~ * ~~~ {.rust}
* let i = str::as_bytes("Hello World") { |bytes| bytes.len() }; * let i = str::as_bytes("Hello World") { |bytes| bytes.len() };
* ~~~ * ~~~
*/ */
@ -2145,7 +2145,7 @@ pub fn as_bytes_slice<'a>(s: &'a str) -> &'a [u8] {
* *
* # Example * # Example
* *
* ~~~ * ~~~ {.rust}
* let s = str::as_c_str("PATH", { |path| libc::getenv(path) }); * let s = str::as_c_str("PATH", { |path| libc::getenv(path) });
* ~~~ * ~~~
*/ */
@ -2184,7 +2184,7 @@ pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
* *
* # Example * # Example
* *
* ~~~ * ~~~ {.rust}
* let string = "a\nb\nc"; * let string = "a\nb\nc";
* let mut lines = ~[]; * let mut lines = ~[];
* for each_line(string) |line| { lines.push(line) } * for each_line(string) |line| { lines.push(line) }

View file

@ -138,7 +138,7 @@ terminate normally, but instead directly return from a function.
# Example # Example
~~~ ~~~ {.rust}
fn choose_weighted_item(v: &[Item]) -> Item { fn choose_weighted_item(v: &[Item]) -> Item {
assert!(!v.is_empty()); assert!(!v.is_empty());
let mut so_far = 0u; let mut so_far = 0u;

View file

@ -977,7 +977,7 @@ pub fn connect<T:Copy>(v: &[~[T]], sep: &T) -> ~[T] {
* *
* Sum all values in the vector [1, 2, 3]: * Sum all values in the vector [1, 2, 3]:
* *
* ~~~ * ~~~ {.rust}
* vec::foldl(0, [1, 2, 3], |a, b| a + *b); * vec::foldl(0, [1, 2, 3], |a, b| a + *b);
* ~~~ * ~~~
* *
@ -1009,7 +1009,7 @@ pub fn foldl<'a, T, U>(z: T, v: &'a [U], p: &fn(t: T, u: &'a U) -> T) -> T {
* *
* Sum all values in the vector [1, 2, 3]: * Sum all values in the vector [1, 2, 3]:
* *
* ~~~ * ~~~ {.rust}
* vec::foldr([1, 2, 3], 0, |a, b| a + *b); * vec::foldr([1, 2, 3], 0, |a, b| a + *b);
* ~~~ * ~~~
* *
@ -1376,10 +1376,8 @@ pub fn reverse<T>(v: &mut [T]) {
* *
* Assume a mutable vector `v` contains `[1,2,3,4,5]`. After the call: * Assume a mutable vector `v` contains `[1,2,3,4,5]`. After the call:
* *
* ~~~ * ~~~ {.rust}
*
* reverse_part(v, 1, 4); * reverse_part(v, 1, 4);
*
* ~~~ * ~~~
* *
* `v` now contains `[1,4,3,2,5]`. * `v` now contains `[1,4,3,2,5]`.
@ -1416,14 +1414,15 @@ pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
* * continue iterating, false to break. * * continue iterating, false to break.
* *
* # Examples * # Examples
* ~~~ *
* ~~~ {.rust}
* [1,2,3].each(|&i| { * [1,2,3].each(|&i| {
* io::println(int::str(i)); * io::println(int::str(i));
* true * true
* }); * });
* ~~~ * ~~~
* *
* ~~~ * ~~~ {.rust}
* [1,2,3,4,5].each(|&i| { * [1,2,3,4,5].each(|&i| {
* if i < 4 { * if i < 4 {
* io::println(int::str(i)); * io::println(int::str(i));
@ -1438,7 +1437,7 @@ pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
* You probably will want to use each with a `for`/`do` expression, depending * You probably will want to use each with a `for`/`do` expression, depending
* on your iteration needs: * on your iteration needs:
* *
* ~~~ * ~~~ {.rust}
* for [1,2,3].each |&i| { * for [1,2,3].each |&i| {
* io::println(int::str(i)); * io::println(int::str(i));
* } * }
@ -1700,7 +1699,7 @@ pub fn each_permutation<T:Copy>(values: &[T], fun: &fn(perm : &[T]) -> bool) ->
* *
* Print the adjacent pairs of a vector (i.e. `[1,2]`, `[2,3]`, `[3,4]`) * Print the adjacent pairs of a vector (i.e. `[1,2]`, `[2,3]`, `[3,4]`)
* *
* ~~~ * ~~~ {.rust}
* for windowed(2, &[1,2,3,4]) |v| { * for windowed(2, &[1,2,3,4]) |v| {
* io::println(fmt!("%?", v)); * io::println(fmt!("%?", v));
* } * }