Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax highlight code examples in docstrings #6771

Merged
merged 1 commit into from
May 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* 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.
*
* ~~~
* ~~~ {.rust}
* extern mod std;
* use std::arc;
* let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
Expand Down Expand Up @@ -370,7 +370,10 @@ pub impl<T:Const + Owned> RWARC<T> {
* 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
* calling downgrade(), after which a &T can be obtained instead.
* ~~~
*
* # Example
*
* ~~~ {.rust}
* do arc.write_downgrade |write_mode| {
* do (&write_mode).write_cond |state, condvar| {
* ... exclusive access with mutable state ...
Expand Down
24 changes: 12 additions & 12 deletions src/libextra/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ impl<'self> ToBase64 for &'self [u8] {
/**
* Turn a vector of `u8` bytes into a base64 string.
*
* *Example*:
* # Example
*
* ~~~~
* ~~~ {.rust}
* extern mod std;
* use std::base64::ToBase64;
*
* fn main () {
* let str = [52,32].to_base64();
* println(fmt!("%s", str));
* }
* ~~~~
* ~~~
*/
fn to_base64(&self) -> ~str {
let mut s = ~"";
Expand Down Expand Up @@ -91,17 +91,17 @@ impl<'self> ToBase64 for &'self str {
* Convert any string (literal, `@`, `&`, or `~`) to base64 encoding.
*
*
* *Example*:
* # Example
*
* ~~~~
* ~~~ {.rust}
* extern mod std;
* use std::base64::ToBase64;
*
* fn main () {
* let str = "Hello, World".to_base64();
* println(fmt!("%s",str));
* }
* ~~~~
* ~~~
*
*/
fn to_base64(&self) -> ~str {
Expand All @@ -118,9 +118,9 @@ impl FromBase64 for ~[u8] {
* Convert base64 `u8` vector into u8 byte values.
* Every 4 encoded characters is converted into 3 octets, modulo padding.
*
* *Example*:
* # Example
*
* ~~~~
* ~~~ {.rust}
* extern mod std;
* use std::base64::ToBase64;
* use std::base64::FromBase64;
Expand All @@ -131,7 +131,7 @@ impl FromBase64 for ~[u8] {
* let bytes = str.from_base64();
* println(fmt!("%?",bytes));
* }
* ~~~~
* ~~~
*/
fn from_base64(&self) -> ~[u8] {
if self.len() % 4u != 0u { fail!("invalid base64 length"); }
Expand Down Expand Up @@ -196,11 +196,11 @@ impl FromBase64 for ~str {
* You can use the `from_bytes` function in `core::str`
* to turn a `[u8]` into a string with characters corresponding to those values.
*
* *Example*:
* # Example
*
* This converts a string literal to base64 and back.
*
* ~~~~
* ~~~ {.rust}
* extern mod std;
* use std::base64::ToBase64;
* use std::base64::FromBase64;
Expand All @@ -214,7 +214,7 @@ impl FromBase64 for ~str {
* let result_str = str::from_bytes(bytes);
* println(fmt!("%s",result_str));
* }
* ~~~~
* ~~~
*/
fn from_base64(&self) -> ~[u8] {
str::to_bytes(*self).from_base64()
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/flatpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ports and channels.

This example sends boxed integers across tasks using serialization.

~~~
~~~ {.rust}
let (port, chan) = serial::pipe_stream();

do task::spawn || {
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* # Example
*
* ~~~
* ~~~ {.rust}
* # fn fib(n: uint) -> uint {42};
* # fn make_a_sandwich() {};
* let mut delayed_fib = std::future::spawn (|| fib(5000) );
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/net_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ fn read_future(sock: &TcpSocket, timeout_msecs: uint)
* Here, the `new_conn` is used in conjunction with `accept` from within
* a task spawned by the `new_connect_cb` passed into `listen`
*
* ~~~~~~~~~~~
* ~~~ {.rust}
* do net::tcp::listen(remote_ip, remote_port, backlog, iotask,
* // this callback is ran once after the connection is successfully
* // set up
Expand Down Expand Up @@ -497,7 +497,7 @@ fn read_future(sock: &TcpSocket, timeout_msecs: uint)
* None => ()
* }
* };
* ~~~~~~~~~~~
* ~~~
*
* # Arguments
*
Expand Down
5 changes: 4 additions & 1 deletion src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ pub impl RWlock {
* 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
* transformed into a "read mode token" by calling downgrade(). Example:
* ~~~
*
* # Example
*
* ~~~ {.rust}
* do lock.write_downgrade |write_mode| {
* do (&write_mode).write_cond |condvar| {
* ... exclusive access ...
Expand Down
63 changes: 50 additions & 13 deletions src/libstd/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ use from_str::FromStr;
* Negation of a boolean value.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::not(true)
* false
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::not(false)
* true
* ~~~
Expand All @@ -57,10 +60,13 @@ pub fn not(v: bool) -> bool { !v }
* Conjunction of two boolean values.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::and(true, false)
* false
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::and(true, true)
* true
* ~~~
Expand All @@ -71,10 +77,13 @@ pub fn and(a: bool, b: bool) -> bool { a && b }
* Disjunction of two boolean values.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::or(true, false)
* true
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::or(false, false)
* false
* ~~~
Expand All @@ -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))`.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::xor(true, false)
* true
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::xor(true, true)
* false
* ~~~
Expand All @@ -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`.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::implies(true, true)
* true
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::implies(true, false)
* false
* ~~~
Expand All @@ -121,10 +135,13 @@ pub fn implies(a: bool, b: bool) -> bool { !a || b }
* Two booleans are equal if they have the same value.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::eq(false, true)
* false
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::eq(false, false)
* true
* ~~~
Expand All @@ -137,10 +154,13 @@ pub fn eq(a: bool, b: bool) -> bool { a == b }
* Two booleans are not equal if they have different values.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::ne(false, true)
* true
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::ne(false, false)
* false
* ~~~
Expand All @@ -151,10 +171,13 @@ pub fn ne(a: bool, b: bool) -> bool { a != b }
* Is a given boolean value true?
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::is_true(true)
* true
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::is_true(false)
* false
* ~~~
Expand All @@ -165,10 +188,13 @@ pub fn is_true(v: bool) -> bool { v }
* Is a given boolean value false?
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::is_false(false)
* true
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::is_false(true)
* false
* ~~~
Expand All @@ -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.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> FromStr::from_str::<bool>("true")
* Some(true)
* ~~~
*
* ~~~ {.rust}
* rusti> FromStr::from_str::<bool>("false")
* Some(false)
* ~~~
*
* ~~~ {.rust}
* rusti> FromStr::from_str::<bool>("not even a boolean")
* None
* ~~~
Expand All @@ -206,10 +237,13 @@ impl FromStr for bool {
* Convert a `bool` to a `str`.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::to_str(true)
* "true"
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::to_str(false)
* "false"
* ~~~
Expand Down Expand Up @@ -237,10 +271,13 @@ pub fn all_values(blk: &fn(v: bool)) {
* Convert a `bool` to a `u8`.
*
* # Examples
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::to_bit(true)
* 1
* ~~~
*
* ~~~ {.rust}
* rusti> std::bool::to_bit(false)
* 0
* ~~~
Expand Down
25 changes: 15 additions & 10 deletions src/libstd/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* # Examples
* ~~~
* # Example
*
* ~~~ {.rust}
* let stdin = core::io::stdin();
* let line = stdin.read_line();
* core::io::print(line);
Expand Down Expand Up @@ -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.
*
* # Examples
* ~~~
* # Example
*
* ~~~ {.rust}
* let stdout = core::io::stdout();
* stdout.write_str("hello\n");
* ~~~
Expand All @@ -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.
*
* # Examples
* ~~~
* # Example
*
* ~~~ {.rust}
* let stderr = core::io::stderr();
* stderr.write_str("hello\n");
* ~~~
Expand All @@ -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
* an implicit newline, please see `println`.
*
* # Examples
* ~~~
* # Example
*
* ~~~ {.rust}
* // print is imported into the prelude, and so is always available.
* print("hello");
* ~~~
Expand All @@ -1612,8 +1616,9 @@ pub fn print(s: &str) {
*
* 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("hello");
* ~~~
Expand Down
Loading