core: Convert to rustdoc

This commit is contained in:
Brian Anderson 2012-03-06 19:09:32 -08:00
parent a0521971b1
commit b22556a6f8
32 changed files with 1077 additions and 2116 deletions

View File

@ -10,55 +10,36 @@ export from_str, to_str, all_values, to_bit;
#[doc = "The type of boolean logic values"]
type t = bool;
#[doc(
brief = "Negation/Inverse"
)]
#[doc = "Negation/Inverse"]
pure fn not(v: t) -> t { !v }
#[doc(
brief = "Conjunction"
)]
#[doc = "Conjunction"]
pure fn and(a: t, b: t) -> t { a && b }
#[doc(
brief = "Disjunction"
)]
#[doc = "Disjunction"]
pure fn or(a: t, b: t) -> t { a || b }
#[doc(
brief = "Exclusive or, i.e. `or(and(a, not(b)), and(not(a), b))`"
)]
#[doc = "Exclusive or, i.e. `or(and(a, not(b)), and(not(a), b))`"]
pure fn xor(a: t, b: t) -> t { (a && !b) || (!a && b) }
#[doc(
brief = "Implication in the logic, i.e. from `a` follows `b`"
)]
#[doc = "Implication in the logic, i.e. from `a` follows `b`"]
pure fn implies(a: t, b: t) -> t { !a || b }
#[doc(
brief = "true if truth values `a` and `b` \
are indistinguishable in the logic"
)]
#[doc = "
true if truth values `a` and `b` are indistinguishable in the logic
"]
pure fn eq(a: t, b: t) -> bool { a == b }
#[doc(
brief = "true if truth values `a` and `b` are distinguishable in the logic"
)]
#[doc = "true if truth values `a` and `b` are distinguishable in the logic"]
pure fn ne(a: t, b: t) -> bool { a != b }
#[doc(
brief = "true if `v` represents truth in the logic"
)]
#[doc = "true if `v` represents truth in the logic"]
pure fn is_true(v: t) -> bool { v }
#[doc(
brief = "true if `v` represents falsehood in the logic"
)]
#[doc = "true if `v` represents falsehood in the logic"]
pure fn is_false(v: t) -> bool { !v }
#[doc(
brief = "Parse logic value from `s`"
)]
#[doc = "Parse logic value from `s`"]
pure fn from_str(s: str) -> option<t> {
alt check s {
"true" { some(true) }
@ -67,23 +48,19 @@ pure fn from_str(s: str) -> option<t> {
}
}
#[doc(
brief = "Convert `v` into a string"
)]
#[doc = "Convert `v` into a string"]
pure fn to_str(v: t) -> str { if v { "true" } else { "false" } }
#[doc(
brief = "Iterates over all truth values by passing them to `blk` \
in an unspecified order"
)]
#[doc = "
Iterates over all truth values by passing them to `blk` in an unspecified
order
"]
fn all_values(blk: fn(v: t)) {
blk(true);
blk(false);
}
#[doc(
brief = "converts truth value to an 8 bit byte"
)]
#[doc = "converts truth value to an 8 bit byte"]
pure fn to_bit(v: t) -> u8 { if v { 1u8 } else { 0u8 } }
#[test]

View File

@ -1,9 +1,9 @@
#[doc = "Operations on shared box types"];
export ptr_eq;
#[doc(
brief = "Determine if two shared boxes point to the same object"
)]
pure fn ptr_eq<T>(a: @T, b: @T) -> bool unchecked {
#[doc = "Determine if two shared boxes point to the same object"];
ptr::addr_of(*a) == ptr::addr_of(*b)
}

View File

@ -45,27 +45,27 @@ import is_XID_start = unicode::derived_property::XID_Start;
import is_XID_continue = unicode::derived_property::XID_Continue;
#[doc(
brief = "Indicates whether a character is in lower case, defined \
in terms of the Unicode General Category 'Ll'."
)]
#[doc = "
Indicates whether a character is in lower case, defined
in terms of the Unicode General Category 'Ll'
"]
pure fn is_lowercase(c: char) -> bool {
ret unicode::general_category::Ll(c);
}
#[doc(
brief = "Indicates whether a character is in upper case, defined \
in terms of the Unicode General Category 'Lu'."
)]
#[doc = "
Indicates whether a character is in upper case, defined
in terms of the Unicode General Category 'Lu'.
"]
pure fn is_uppercase(c: char) -> bool {
ret unicode::general_category::Lu(c);
}
#[doc(
brief = "Indicates whether a character is whitespace, defined in \
terms of the Unicode General Categories 'Zs', 'Zl', 'Zp' \
additional 'Cc'-category control codes in the range [0x09, 0x0d]"
)]
#[doc = "
Indicates whether a character is whitespace, defined in
terms of the Unicode General Categories 'Zs', 'Zl', 'Zp'
additional 'Cc'-category control codes in the range [0x09, 0x0d]
"]
pure fn is_whitespace(c: char) -> bool {
ret ('\x09' <= c && c <= '\x0d')
|| unicode::general_category::Zs(c)
@ -73,11 +73,11 @@ pure fn is_whitespace(c: char) -> bool {
|| unicode::general_category::Zp(c);
}
#[doc(
brief = "Indicates whether a character is alphanumeric, defined \
in terms of the Unicode General Categories 'Nd', \
'Nl', 'No' and the Derived Core Property 'Alphabetic'."
)]
#[doc = "
Indicates whether a character is alphanumeric, defined
in terms of the Unicode General Categories 'Nd',
'Nl', 'No' and the Derived Core Property 'Alphabetic'.
"]
pure fn is_alphanumeric(c: char) -> bool {
ret unicode::derived_property::Alphabetic(c) ||
unicode::general_category::Nd(c) ||
@ -85,26 +85,32 @@ pure fn is_alphanumeric(c: char) -> bool {
unicode::general_category::No(c);
}
#[doc( brief = "Indicates whether the character is an ASCII character" )]
#[doc = "Indicates whether the character is an ASCII character"]
pure fn is_ascii(c: char) -> bool {
c - ('\x7F' & c) == '\x00'
}
#[doc( brief = "Indicates whether the character is numeric (Nd, Nl, or No)" )]
#[doc = "Indicates whether the character is numeric (Nd, Nl, or No)"]
pure fn is_digit(c: char) -> bool {
ret unicode::general_category::Nd(c) ||
unicode::general_category::Nl(c) ||
unicode::general_category::No(c);
}
#[doc(
brief = "Convert a char to the corresponding digit. \
Safety note: This function fails if `c` is not a valid char",
return = "If `c` is between '0' and '9', the corresponding value \
between 0 and 9. If `c` is 'a' or 'A', 10. If `c` is \
'b' or 'B', 11, etc. Returns none if the char does not \
refer to a digit in the given radix."
)]
#[doc = "
Convert a char to the corresponding digit.
# Safety note
This function fails if `c` is not a valid char
# Return value
If `c` is between '0' and '9', the corresponding value
between 0 and 9. If `c` is 'a' or 'A', 10. If `c` is
'b' or 'B', 11, etc. Returns none if the char does not
refer to a digit in the given radix.
"]
pure fn to_digit(c: char, radix: uint) -> option<uint> {
let val = alt c {
'0' to '9' { c as uint - ('0' as uint) }
@ -119,9 +125,7 @@ pure fn to_digit(c: char, radix: uint) -> option<uint> {
/*
FIXME: works only on ASCII
*/
#[doc(
brief = "Convert a char to the corresponding lower case."
)]
#[doc = "Convert a char to the corresponding lower case."]
pure fn to_lower(c: char) -> char {
alt c {
'A' to 'Z' { ((c as u8) + 32u8) as char }
@ -132,9 +136,7 @@ pure fn to_lower(c: char) -> char {
/*
FIXME: works only on ASCII
*/
#[doc(
brief = "Convert a char to the corresponding upper case."
)]
#[doc = "Convert a char to the corresponding upper case."]
pure fn to_upper(c: char) -> char {
alt c {
'a' to 'z' { ((c as u8) - 32u8) as char }
@ -142,10 +144,13 @@ pure fn to_upper(c: char) -> char {
}
}
#[doc(
brief = "Compare two chars.",
return = "-1 if a<b, 0 if a==b, +1 if a>b"
)]
#[doc = "
Compare two chars
# Return value
-1 if a < b, 0 if a == b, +1 if a > b
"]
pure fn cmp(a: char, b: char) -> int {
ret if b > a { -1 }
else if b < a { 1 }

View File

@ -1,6 +1,5 @@
#[doc(
brief = "Communication between tasks",
desc = "
#[doc = "
Communication between tasks
Communication between tasks is facilitated by ports (in the receiving
task), and channels (in the sending task). Any number of channels may
@ -11,15 +10,19 @@ vectors, strings, and records, tags, tuples and unique boxes (`~T`)
thereof. Most notably, shared boxes (`@T`) may not be transmitted
across channels.
Example:
# Example
let p = comm::port();
task::spawn(comm::chan(p), fn (c: chan<str>) {
comm::send(c, \"Hello, World\");
});
io::println(comm::recv(p));
~~~
let po = comm::port();
let ch = comm::chan(po);
")];
task::spawn {||
comm::send(ch, \"Hello, World\");
});
io::println(comm::recv(p));
~~~
"];
import sys;
import task;
@ -65,18 +68,16 @@ type port_id = int;
// It's critical that this only have one variant, so it has a record
// layout, and will work in the rust_task structure in task.rs.
#[doc(
brief = "A communication endpoint that can send messages. \
Channels send messages to ports.",
desc = "Each channel is bound to a port when the channel is \
constructed, so the destination port for a channel \
must exist before the channel itself. \
Channels are weak: a channel does not keep the port it \
is bound to alive. If a channel attempts to send data \
to a dead port that data will be silently dropped. \
Channels may be duplicated and themselves transmitted \
over other channels."
)]
#[doc = "
A communication endpoint that can send messages
Each channel is bound to a port when the channel is constructed, so
the destination port for a channel must exist before the channel
itself. Channels are weak: a channel does not keep the port it is
bound to alive. If a channel attempts to send data to a dead port that
data will be silently dropped. Channels may be duplicated and
themselves transmitted over other channels.
"]
enum chan<T: send> {
chan_t(task_id, port_id)
}
@ -104,21 +105,19 @@ resource port_ptr<T: send>(po: *rust_port) {
rustrt::del_port(po);
}
#[doc(
brief = "A communication endpoint that can receive messages. \
Ports receive messages from channels.",
desc = "Each port has a unique per-task identity and may not \
be replicated or transmitted. If a port value is \
copied, both copies refer to the same port. \
Ports may be associated with multiple <chan>s."
)]
#[doc = "
A communication endpoint that can receive messages
Each port has a unique per-task identity and may not be replicated or
transmitted. If a port value is copied, both copies refer to the same
port. Ports may be associated with multiple `chan`s.
"]
enum port<T: send> { port_t(@port_ptr<T>) }
#[doc(
brief = "Sends data over a channel. The sent data is moved \
into the channel, whereupon the caller loses \
access to it."
)]
#[doc = "
Sends data over a channel. The sent data is moved into the channel,
whereupon the caller loses access to it.
"]
fn send<T: send>(ch: chan<T>, -data: T) {
let chan_t(t, p) = ch;
let res = rustrt::chan_id_send(sys::get_type_desc::<T>(), t, p, data);
@ -129,23 +128,18 @@ fn send<T: send>(ch: chan<T>, -data: T) {
task::yield();
}
#[doc(
brief = "Constructs a port."
)]
#[doc = "Constructs a port"]
fn port<T: send>() -> port<T> {
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>())))
}
#[doc(
brief = "Receive from a port. \
If no data is available on the port then the task will \
block until data becomes available."
)]
#[doc = "
Receive from a port. If no data is available on the port then the
task will block until data becomes available.
"]
fn recv<T: send>(p: port<T>) -> T { recv_(***p) }
#[doc(
brief = "Receive on a raw port pointer"
)]
#[doc = "Receive on a raw port pointer"]
fn recv_<T: send>(p: *rust_port) -> T {
// FIXME: Due to issue 1185 we can't use a return pointer when
// calling C code, and since we can't create our own return
@ -218,10 +212,10 @@ fn peek<T: send>(p: port<T>) -> bool {
rustrt::rust_port_size(***p) != 0u as ctypes::size_t
}
#[doc(
brief = "Constructs a channel. The channel is bound to the \
port used to construct it."
)]
#[doc = "
Constructs a channel. The channel is bound to the port used to
construct it.
"]
fn chan<T: send>(p: port<T>) -> chan<T> {
chan_t(rustrt::get_task_id(), rustrt::get_port_id(***p))
}

View File

@ -10,9 +10,8 @@
// Don't link to core. We are core.
#[no_core];
#[doc(
brief = "The Rust core library",
desc = "
#[doc = "
The Rust core library
The core library provides functionality that is closely tied to the Rust
built-in types and runtime services, or that is used in nearly every
@ -24,9 +23,8 @@ as though the user had written the following:
use core;
import core::*;
This behavior can be disabled with the `no_core` crate attribute."
)];
This behavior can be disabled with the `no_core` crate attribute.
"];
export int, i8, i16, i32, i64;
export uint, u8, u16, u32, u64;

View File

@ -40,13 +40,11 @@ mod std {
import std::test;
}
/*
Function: unreachable
#[doc = "
A standard function to use to indicate unreachable code. Because the
function is guaranteed to fail typestate will correctly identify
any code paths following the appearance of this function as unreachable.
*/
"]
fn unreachable() -> ! {
fail "Internal error: entered unreachable code";
}

View File

@ -19,103 +19,73 @@ export enum;
#[doc = "A signed integer with the same size as a C `char`."]
type c_char = i8;
#[doc(
brief = "A signed integer with the same size as a C `int`."
)]
#[doc = "A signed integer with the same size as a C `int`."]
type c_int = i32;
#[doc(
brief = "An unsigned integer with the same size as a C `unsigned int`."
)]
#[doc = "An unsigned integer with the same size as a C `unsigned int`."]
type c_uint = u32;
#[doc(
brief = "A signed integer with the same size as a C `long`."
)]
#[doc = "A signed integer with the same size as a C `long`."]
type long = int;
#[doc(
brief = "A signed integer with the same size as a C `long long`."
)]
#[doc = "A signed integer with the same size as a C `long long`."]
type longlong = i64;
#[doc(
brief = "A signed integer with the same size as a C `unsigned int`."
)]
#[doc = "A signed integer with the same size as a C `unsigned int`."]
type unsigned = u32;
#[doc(
brief = "A signed integer with the same size as a C `unsigned long`."
)]
#[doc = "A signed integer with the same size as a C `unsigned long`."]
type ulong = uint;
#[doc(
brief = "A signed integer with the same size as a C `unsigned long long`."
)]
#[doc = "A signed integer with the same size as a C `unsigned long long`."]
type ulonglong = u64;
#[doc(
brief = "A signed integer with the same size as a pointer. \
This is guaranteed to always be the same type as a \
Rust `int`."
)]
#[doc = "
A signed integer with the same size as a pointer. This is guaranteed
to always be the same type as a Rust `int`.
"]
type intptr_t = uint; // FIXME: int
#[doc(
brief = "An unsigned integer with the same size as a pointer. \
This is guaranteed to always be the same type as a Rust \
`uint`."
)]
#[doc = "
An unsigned integer with the same size as a pointer. This is
guaranteed to always be the same type as a Rust `uint`.
"]
type uintptr_t = uint;
type uint32_t = u32;
#[doc(
brief = "A type, a pointer to which can be used as C `void *`.",
desc = "The void type cannot be constructed or destructured, \
but using pointers to this type when interoperating \
with C void pointers can help in documentation."
)]
#[doc = "
A type, a pointer to which can be used as C `void *`.
The void type cannot be constructed or destructured, but using
pointers to this type when interoperating with C void pointers can
help in documentation.
"]
enum void {}
#[doc(
brief = "A float value with the same size as a C `float`."
)]
#[doc = "A float value with the same size as a C `float`."]
type c_float = f32;
#[doc(
brief = "A float value with the same size as a C `double`."
)]
#[doc = "A float value with the same size as a C `double`."]
type c_double = f64;
#[doc(
brief = "An unsigned integer corresponding to the C `size_t`."
)]
#[doc = "An unsigned integer corresponding to the C `size_t`."]
type size_t = uint;
#[doc(
brief = "A signed integer corresponding to the C `ssize_t`."
)]
#[doc = "A signed integer corresponding to the C `ssize_t`."]
type ssize_t = int;
#[doc(
brief = "An unsigned integer corresponding to the C `off_t`."
)]
#[doc = "An unsigned integer corresponding to the C `off_t`."]
type off_t = uint;
#[doc(
brief = "A type that can be used for C file descriptors."
)]
#[doc = "A type that can be used for C file descriptors."]
type fd_t = i32; // not actually a C type, but should be.
#[doc(
brief = "A type for representing process ID's, corresponding to C `pid_t`."
)]
#[doc = "A type for representing process ID's, corresponding to C `pid_t`."]
type pid_t = i32;
#[doc(
brief = "An unsigned integer with the same size as a C enum. \
enum is implementation-defined, but is 32-bits in \
practice"
)]
#[doc = "
An unsigned integer with the same size as a C enum. enum is
implementation-defined, but is 32-bits in practice
"]
type enum = u32;

View File

@ -1,45 +1,27 @@
/*
Module: either
#[doc = "A type that represents one of two alternatives"];
A type that represents one of two alternatives
*/
/*
Tag: t
The either type
*/
#[doc = "The either type"]
enum t<T, U> {
/* Variant: left */
left(T),
/* Variant: right */
right(U)
}
/* Section: Operations */
fn either<T, U, V>(f_left: fn(T) -> V,
f_right: fn(U) -> V, value: t<T, U>) -> V {
#[doc = "
Applies a function based on the given either value
/*
Function: either
If `value` is left(T) then `f_left` is applied to its contents, if `value`
is right(U) then `f_right` is applied to its contents, and the result is
returned.
"];
Applies a function based on the given either value
If `value` is left(T) then `f_left` is applied to its contents, if
`value` is right(U) then `f_right` is applied to its contents, and
the result is returned.
*/
fn either<T, U,
V>(f_left: fn(T) -> V, f_right: fn(U) -> V, value: t<T, U>) ->
V {
alt value { left(l) { f_left(l) } right(r) { f_right(r) } }
}
/*
Function: lefts
Extracts from a vector of either all the left values.
*/
fn lefts<T: copy, U>(eithers: [t<T, U>]) -> [T] {
#[doc = "Extracts from a vector of either all the left values"];
let mut result: [T] = [];
for elt: t<T, U> in eithers {
alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } }
@ -47,12 +29,9 @@ fn lefts<T: copy, U>(eithers: [t<T, U>]) -> [T] {
ret result;
}
/*
Function: rights
Extracts from a vector of either all the right values
*/
fn rights<T, U: copy>(eithers: [t<T, U>]) -> [U] {
#[doc = "Extracts from a vector of either all the right values"];
let mut result: [U] = [];
for elt: t<T, U> in eithers {
alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } }
@ -60,16 +39,15 @@ fn rights<T, U: copy>(eithers: [t<T, U>]) -> [U] {
ret result;
}
/*
Function: partition
Extracts from a vector of either all the left values and right values
Returns a structure containing a vector of left values and a vector of
right values.
*/
fn partition<T: copy, U: copy>(eithers: [t<T, U>])
-> {lefts: [T], rights: [U]} {
#[doc = "
Extracts from a vector of either all the left values and right values
Returns a structure containing a vector of left values and a vector of
right values.
"];
let mut lefts: [T] = [];
let mut rights: [U] = [];
for elt: t<T, U> in eithers {
@ -78,59 +56,41 @@ fn partition<T: copy, U: copy>(eithers: [t<T, U>])
ret {lefts: lefts, rights: rights};
}
/*
Function: flip
Flips between left and right of a given either
*/
pure fn flip<T: copy, U: copy>(eith: t<T, U>) -> t<U, T> {
#[doc = "Flips between left and right of a given either"];
alt eith {
right(r) { left(r) }
left(l) { right(l) }
}
}
/*
Function: to_result
Converts either::t to a result::t, making the "right" choice
an ok result, and the "left" choice a fail
*/
pure fn to_result<T: copy, U: copy>(eith: t<T, U>) -> result::t<U, T> {
#[doc = "
Converts either::t to a result::t
Converts an `either` type to a `result` type, making the \"right\" choice
an ok result, and the \"left\" choice a fail
"];
alt eith {
right(r) { result::ok(r) }
left(l) { result::err(l) }
}
}
/*
Function: is_left
Checks whether the given value is a left
*/
pure fn is_left<T, U>(eith: t<T, U>) -> bool {
#[doc = "Checks whether the given value is a left"];
alt eith { left(_) { true } _ { false } }
}
/*
Function: is_right
Checks whether the given value is a right
*/
pure fn is_right<T, U>(eith: t<T, U>) -> bool {
#[doc = "Checks whether the given value is a right"];
alt eith { right(_) { true } _ { false } }
}
//
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//
#[test]
fn test_either_left() {
let val = left(10);
@ -223,3 +183,13 @@ fn test_partition_empty() {
assert (vec::len(result.lefts) == 0u);
assert (vec::len(result.rights) == 0u);
}
//
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//

View File

@ -1,3 +1,5 @@
#[doc(hidden)];
/*
Syntax Extension: fmt

View File

@ -58,56 +58,49 @@ pure fn gt(x: f32, y: f32) -> bool { ret x > y; }
// FIXME replace the predicates below with llvm intrinsics or calls
// to the libmath macros in the rust runtime for performance
#[doc(
brief = "Returns true if `x` is a positive number, including +0.0f320 \
and +Infinity."
)]
#[doc = "
Returns true if `x` is a positive number, including +0.0f320 and +Infinity
"]
pure fn is_positive(x: f32) -> bool
{ ret x > 0.0f32 || (1.0f32/x) == infinity; }
#[doc(
brief = "Returns true if `x` is a negative number, including -0.0f320 \
and -Infinity."
)]
#[doc = "
Returns true if `x` is a negative number, including -0.0f320 and -Infinity
"]
pure fn is_negative(x: f32) -> bool
{ ret x < 0.0f32 || (1.0f32/x) == neg_infinity; }
#[doc(
brief = "Returns true if `x` is a negative number, including \
-0.0f320 and -Infinity. (This is the same as \
`f32::negative`.)"
)]
#[doc = "
Returns true if `x` is a negative number, including -0.0f320 and -Infinity
This is the same as `f32::is_negative`.
"]
pure fn is_nonpositive(x: f32) -> bool {
ret x < 0.0f32 || (1.0f32/x) == neg_infinity;
}
#[doc(
brief = "Returns true if `x` is a positive number, \
including +0.0f320 and +Infinity. (This is \
the same as `f32::positive`.)"
)]
#[doc = "
Returns true if `x` is a positive number, including +0.0f320 and +Infinity
This is the same as `f32::is_positive`.)
"]
pure fn is_nonnegative(x: f32) -> bool {
ret x > 0.0f32 || (1.0f32/x) == infinity;
}
#[doc(
brief = "Returns true if `x` is a zero number \
(positive or negative zero)"
)]
#[doc = "
Returns true if `x` is a zero number (positive or negative zero)
"]
pure fn is_zero(x: f32) -> bool {
ret x == 0.0f32 || x == -0.0f32;
}
#[doc(
brief = "Returns true if `x`is an infinite number"
)]
#[doc = "Returns true if `x`is an infinite number"]
pure fn is_infinite(x: f32) -> bool {
ret x == infinity || x == neg_infinity;
}
#[doc(
brief = "Returns true if `x`is a finite number"
)]
#[doc = "Returns true if `x`is a finite number"]
pure fn is_finite(x: f32) -> bool {
ret !(is_NaN(x) || is_infinite(x));
}
@ -118,69 +111,43 @@ pure fn is_finite(x: f32) -> bool {
mod consts {
// FIXME replace with mathematical constants from cmath
#[doc(
brief = "Archimedes' constant"
)]
#[doc = "Archimedes' constant"]
const pi: f32 = 3.14159265358979323846264338327950288_f32;
#[doc(
brief = "pi/2.0"
)]
#[doc = "pi/2.0"]
const frac_pi_2: f32 = 1.57079632679489661923132169163975144_f32;
#[doc(
brief = "pi/4.0"
)]
#[doc = "pi/4.0"]
const frac_pi_4: f32 = 0.785398163397448309615660845819875721_f32;
#[doc(
brief = "1.0/pi"
)]
#[doc = "1.0/pi"]
const frac_1_pi: f32 = 0.318309886183790671537767526745028724_f32;
#[doc(
brief = "2.0/pi"
)]
#[doc = "2.0/pi"]
const frac_2_pi: f32 = 0.636619772367581343075535053490057448_f32;
#[doc(
brief = "2.0/sqrt(pi)"
)]
#[doc = "2.0/sqrt(pi)"]
const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517_f32;
#[doc(
brief = "sqrt(2.0)"
)]
#[doc = "sqrt(2.0)"]
const sqrt2: f32 = 1.41421356237309504880168872420969808_f32;
#[doc(
brief = "1.0/sqrt(2.0)"
)]
#[doc = "1.0/sqrt(2.0)"]
const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039_f32;
#[doc(
brief = "Euler's number"
)]
#[doc = "Euler's number"]
const e: f32 = 2.71828182845904523536028747135266250_f32;
#[doc(
brief = "log2(e)"
)]
#[doc = "log2(e)"]
const log2_e: f32 = 1.44269504088896340735992468100189214_f32;
#[doc(
brief = "log10(e)"
)]
#[doc = "log10(e)"]
const log10_e: f32 = 0.434294481903251827651128918916605082_f32;
#[doc(
brief = "ln(2.0)"
)]
#[doc = "ln(2.0)"]
const ln_2: f32 = 0.693147180559945309417232121458176568_f32;
#[doc(
brief = "ln(10.0)"
)]
#[doc = "ln(10.0)"]
const ln_10: f32 = 2.30258509299404568401799145468436421_f32;
}

View File

@ -76,56 +76,47 @@ pure fn ge(x: f64, y: f64) -> bool { ret x >= y; }
pure fn gt(x: f64, y: f64) -> bool { ret x > y; }
#[doc(
brief = "Returns true if `x` is a positive number, including \
+0.0f640 and +Infinity."
)]
#[doc = "
Returns true if `x` is a positive number, including +0.0f640 and +Infinity.
"]
pure fn is_positive(x: f64) -> bool
{ ret x > 0.0f64 || (1.0f64/x) == infinity; }
#[doc(
brief = "Returns true if `x` is a negative number, including \
-0.0f640 and -Infinity."
)]
#[doc = "
Returns true if `x` is a negative number, including -0.0f640 and -Infinity
"]
pure fn is_negative(x: f64) -> bool
{ ret x < 0.0f64 || (1.0f64/x) == neg_infinity; }
#[doc(
brief = "Returns true if `x` is a negative number, including \
-0.0f640 and -Infinity. (This is the same as \
`f64::negative`.)"
)]
#[doc = "
Returns true if `x` is a negative number, including -0.0f640 and -Infinity
This is the same as `f64::is_negative`.
"]
pure fn is_nonpositive(x: f64) -> bool {
ret x < 0.0f64 || (1.0f64/x) == neg_infinity;
}
#[doc(
brief = "Returns true if `x` is a positive number, including \
+0.0f640 and +Infinity.(This is the same as \
`f64::positive`.)"
)]
#[doc = "
Returns true if `x` is a positive number, including +0.0f640 and +Infinity
This is the same as `f64::positive`.
"]
pure fn is_nonnegative(x: f64) -> bool {
ret x > 0.0f64 || (1.0f64/x) == infinity;
}
#[doc(
brief = "Returns true if `x` is a zero number (positive or \
negative zero)"
)]
#[doc = "Returns true if `x` is a zero number (positive or negative zero)"]
pure fn is_zero(x: f64) -> bool {
ret x == 0.0f64 || x == -0.0f64;
}
#[doc(
brief = "Returns true if `x`is an infinite number."
)]
#[doc = "Returns true if `x`is an infinite number"]
pure fn is_infinite(x: f64) -> bool {
ret x == infinity || x == neg_infinity;
}
#[doc(
brief = "Returns true if `x`is a finite number."
)]
#[doc = "Returns true if `x`is a finite number"]
pure fn is_finite(x: f64) -> bool {
ret !(is_NaN(x) || is_infinite(x));
}
@ -137,69 +128,43 @@ mod consts {
// FIXME replace with mathematical constants from cmath
#[doc(
brief = "Archimedes' constant"
)]
#[doc = "Archimedes' constant"]
const pi: f64 = 3.14159265358979323846264338327950288_f64;
#[doc(
brief = "pi/2.0"
)]
#[doc = "pi/2.0"]
const frac_pi_2: f64 = 1.57079632679489661923132169163975144_f64;
#[doc(
brief = "pi/4.0"
)]
#[doc = "pi/4.0"]
const frac_pi_4: f64 = 0.785398163397448309615660845819875721_f64;
#[doc(
brief = "1.0/pi"
)]
#[doc = "1.0/pi"]
const frac_1_pi: f64 = 0.318309886183790671537767526745028724_f64;
#[doc(
brief = "2.0/pi"
)]
#[doc = "2.0/pi"]
const frac_2_pi: f64 = 0.636619772367581343075535053490057448_f64;
#[doc(
brief = "2.0/sqrt(pi)"
)]
#[doc = "2.0/sqrt(pi)"]
const frac_2_sqrtpi: f64 = 1.12837916709551257389615890312154517_f64;
#[doc(
brief = "sqrt(2.0)"
)]
#[doc = "sqrt(2.0)"]
const sqrt2: f64 = 1.41421356237309504880168872420969808_f64;
#[doc(
brief = "1.0/sqrt(2.0)"
)]
#[doc = "1.0/sqrt(2.0)"]
const frac_1_sqrt2: f64 = 0.707106781186547524400844362104849039_f64;
#[doc(
brief = "Euler's number"
)]
#[doc = "Euler's number"]
const e: f64 = 2.71828182845904523536028747135266250_f64;
#[doc(
brief = "log2(e)"
)]
#[doc = "log2(e)"]
const log2_e: f64 = 1.44269504088896340735992468100189214_f64;
#[doc(
brief = "log10(e)"
)]
#[doc = "log10(e)"]
const log10_e: f64 = 0.434294481903251827651128918916605082_f64;
#[doc(
brief = "ln(2.0)"
)]
#[doc = "ln(2.0)"]
const ln_2: f64 = 0.693147180559945309417232121458176568_f64;
#[doc(
brief = "ln(10.0)"
)]
#[doc = "ln(10.0)"]
const ln_10: f64 = 2.30258509299404568401799145468436421_f64;
}

View File

@ -1,9 +1,5 @@
#[doc = "Operations and constants for `float`"];
/*
Module: float
*/
// FIXME find out why these have to be exported explicitly
export to_str_common, to_str_exact, to_str, from_str;
@ -36,17 +32,15 @@ type t = float;
* Section: String Conversions
*/
/*
Function: to_str_common
#[doc = "
Converts a float to a string
Parameters:
# Arguments
num - The float value
digits - The number of significant digits
exact - Whether to enforce the exact number of significant digits
*/
* num - The float value
* digits - The number of significant digits
* exact - Whether to enforce the exact number of significant digits
"]
fn to_str_common(num: float, digits: uint, exact: bool) -> str {
if is_NaN(num) { ret "NaN"; }
let mut (num, accum) = if num < 0.0 { (-num, "-") } else { (num, "") };
@ -69,17 +63,15 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> str {
}
/*
Function: to_str
#[doc = "
Converts a float to a string with exactly the number of
provided significant digits
Converts a float to a string with exactly the number of provided significant
digits
# Arguments
Parameters:
num - The float value
digits - The number of significant digits
*/
* num - The float value
* digits - The number of significant digits
"]
fn to_str_exact(num: float, digits: uint) -> str {
to_str_common(num, digits, true)
}
@ -90,47 +82,45 @@ fn test_to_str_exact_do_decimal() {
assert s == "5.0000";
}
/*
Function: to_str
Converts a float to a string with a maximum number of significant digits
#[doc = "
Converts a float to a string with a maximum number of
significant digits
Parameters:
# Arguments
num - The float value
digits - The number of significant digits
*/
* num - The float value
* digits - The number of significant digits
"]
fn to_str(num: float, digits: uint) -> str {
to_str_common(num, digits, false)
}
/*
Function: from_str
#[doc = "
Convert a string to a float
This function accepts strings such as
* "3.14"
* "+3.14", equivalent to "3.14"
* "-3.14"
* "2.5E10", or equivalently, "2.5e10"
* "2.5E-10"
* "", or, equivalently, "." (understood as 0)
* "5."
* ".5", or, equivalently, "0.5"
* '3.14'
* '+3.14', equivalent to '3.14'
* '-3.14'
* '2.5E10', or equivalently, '2.5e10'
* '2.5E-10'
* '', or, equivalently, '.' (understood as 0)
* '5.'
* '.5', or, equivalently, '0.5'
Leading and trailing whitespace are ignored.
Parameters:
# Arguments
num - A string
* num - A string
Returns:
# Return value
none if the string did not represent a valid number.
Otherwise, some(n) where n is the floating-point
number represented by [num].
*/
`none` if the string did not represent a valid number. Otherwise, `some(n)`
where `n` is the floating-point number represented by `[num]`.
"]
fn from_str(num: str) -> option<float> {
let mut pos = 0u; //Current byte position in the string.
//Used to walk the string in O(n).
@ -256,18 +246,18 @@ fn from_str(num: str) -> option<float> {
* Section: Arithmetics
*/
/*
Function: pow_with_uint
#[doc = "
Compute the exponentiation of an integer by another integer as a float
Compute the exponentiation of an integer by another integer as a float.
# Arguments
Parameters:
x - The base.
pow - The exponent.
* x - The base
* pow - The exponent
Returns:
<NaN> of both `x` and `pow` are `0u`, otherwise `x^pow`.
*/
# Return value
`NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
"]
fn pow_with_uint(base: uint, pow: uint) -> float {
if base == 0u {
if pow == 0u {

View File

@ -1,14 +1,14 @@
#[doc = "
A type representing values that may be computed concurrently and
operations for working with them.
Example:
> let delayed_fib = future::spawn {|| fib(5000) };
> make_a_sandwitch();
> io::println(#fmt(\"fib(5000) = %?\", delayed_fib.get()))
# Example
~~~
let delayed_fib = future::spawn {|| fib(5000) };
make_a_sandwitch();
io::println(#fmt(\"fib(5000) = %?\", delayed_fib.get()))
~~~
"];
export future;
@ -45,10 +45,10 @@ impl future<A:send> for future<A> {
fn from_value<A>(+val: A) -> future<A> {
#[doc = "
Create a future from a value
Create a future from a value. The value is immediately available
and calling `get` later will not block.
The value is immediately available and calling `get` later will
not block.
"];
future({
@ -58,11 +58,10 @@ fn from_value<A>(+val: A) -> future<A> {
fn from_port<A:send>(-port: comm::port<A>) -> future<A> {
#[doc = "
Create a future from a port
Create a future from a port. The first time that the value is
requested the task will block waiting for the result to be
received on the port.
The first time that the value is requested the task will block
waiting for the result to be received on the port.
"];
from_fn {||
@ -72,12 +71,11 @@ fn from_port<A:send>(-port: comm::port<A>) -> future<A> {
fn from_fn<A>(f: fn@() -> A) -> future<A> {
#[doc = "
Create a future from a function.
Create a future from a function. The first time that the value is
requested it will be retreived by calling the function.
Note that this function is a local function. It is not spawned into
another task.
The first time that the value is requested it will be retreived by
calling the function. Note that this function is a local
function. It is not spawned into another task.
"];
future({
@ -87,10 +85,10 @@ fn from_fn<A>(f: fn@() -> A) -> future<A> {
fn spawn<A:send>(+blk: fn~() -> A) -> future<A> {
#[doc = "
Create a future from a unique closure.
Create a future from a unique closure. The closure will be run
in a new task and its result used as the value of the future.
The closure will be run in a new task and its result used as the
value of the future.
"];
let mut po = comm::port();

View File

@ -1,25 +1,11 @@
#[doc = "Operations and constants for `int`"];
/*
Module: int
*/
/*
Const: min_value
The minumum value of an integer
*/
#[cfg(target_arch="x86")]
const min_value: int = -1 << 31;
#[cfg(target_arch="x86_64")]
const min_value: int = -1 << 63;
/*
Const: max_value
The maximum value of an integer
*/
// FIXME: Find another way to access the machine word size in a const expr
#[cfg(target_arch="x86")]
const max_value: int = (-1 << 31)-1;
@ -30,80 +16,43 @@ const max_value: int = (-1 << 63)-1;
pure fn min(x: int, y: int) -> int { if x < y { x } else { y } }
pure fn max(x: int, y: int) -> int { if x > y { x } else { y } }
/* Function: add */
pure fn add(x: int, y: int) -> int { ret x + y; }
/* Function: sub */
pure fn sub(x: int, y: int) -> int { ret x - y; }
/* Function: mul */
pure fn mul(x: int, y: int) -> int { ret x * y; }
/* Function: div */
pure fn div(x: int, y: int) -> int { ret x / y; }
/* Function: rem */
pure fn rem(x: int, y: int) -> int { ret x % y; }
/* Predicate: lt */
pure fn lt(x: int, y: int) -> bool { ret x < y; }
/* Predicate: le */
pure fn le(x: int, y: int) -> bool { ret x <= y; }
/* Predicate: eq */
pure fn eq(x: int, y: int) -> bool { ret x == y; }
/* Predicate: ne */
pure fn ne(x: int, y: int) -> bool { ret x != y; }
/* Predicate: ge */
pure fn ge(x: int, y: int) -> bool { ret x >= y; }
/* Predicate: gt */
pure fn gt(x: int, y: int) -> bool { ret x > y; }
/* Predicate: positive */
pure fn positive(x: int) -> bool { ret x > 0; }
/* Predicate: negative */
pure fn negative(x: int) -> bool { ret x < 0; }
/* Predicate: nonpositive */
pure fn nonpositive(x: int) -> bool { ret x <= 0; }
/* Predicate: nonnegative */
pure fn nonnegative(x: int) -> bool { ret x >= 0; }
// FIXME: Make sure this works with negative integers.
/*
Function: hash
Produce a uint suitable for use in a hash table
*/
#[doc = "Produce a uint suitable for use in a hash table"]
fn hash(x: int) -> uint { ret x as uint; }
/*
Function: range
Iterate over the range [`lo`..`hi`)
*/
#[doc = "Iterate over the range `[lo..hi)`"]
fn range(lo: int, hi: int, it: fn(int)) {
let mut i = lo;
while i < hi { it(i); i += 1; }
}
/*
Function: parse_buf
#[doc = "
Parse a buffer of bytes
Parameters:
# Arguments
buf - A byte buffer
radix - The base of the number
*/
* buf - A byte buffer
* radix - The base of the number
"]
fn parse_buf(buf: [u8], radix: uint) -> option<int> {
if vec::len(buf) == 0u { ret none; }
let mut i = vec::len(buf) - 1u;
@ -127,18 +76,10 @@ fn parse_buf(buf: [u8], radix: uint) -> option<int> {
fail;
}
/*
Function: from_str
Parse a string to an int
*/
#[doc = "Parse a string to an int"]
fn from_str(s: str) -> option<int> { parse_buf(str::bytes(s), 10u) }
/*
Function: to_str
Convert to a string in a given base
*/
#[doc = "Convert to a string in a given base"]
fn to_str(n: int, radix: uint) -> str {
assert (0u < radix && radix <= 16u);
ret if n < 0 {
@ -146,18 +87,10 @@ fn to_str(n: int, radix: uint) -> str {
} else { uint::to_str(n as uint, radix) };
}
/*
Function: str
Convert to a string
*/
#[doc = "Convert to a string"]
fn str(i: int) -> str { ret to_str(i, 10u); }
/*
Function: pow
Returns `base` raised to the power of `exponent`
*/
#[doc = "Returns `base` raised to the power of `exponent`"]
fn pow(base: int, exponent: uint) -> int {
if exponent == 0u { ret 1; } //Not mathemtically true if [base == 0]
if base == 0 { ret 0; }

View File

@ -13,14 +13,13 @@ fn console_on() {
rustrt::rust_log_console_on();
}
#[doc(
brief =
"Turns off logging to stdout globally",
desc =
"Turns off the console unless the user has overridden the \
runtime environment's logging spec, e.g. by setting \
the RUST_LOG environment variable"
)]
#[doc = "
Turns off logging to stdout globally
Turns off the console unless the user has overridden the
runtime environment's logging spec, e.g. by setting
the RUST_LOG environment variable
"]
fn console_off() {
rustrt::rust_log_console_off();
}

View File

@ -1,19 +1,13 @@
// Generic functions that have been defined for all numeric types
//
// (may very well go away again soon)
#[doc = "
Generic functions that have been defined for all numeric types
/*
Function: min
(may very well go away again soon)
"];
Returns the minimum of two values
*/
#[doc = "Returns the minimum of two values"]
pure fn min<T: copy>(x: T, y: T) -> T { if x < y { x } else { y} }
/*
Function: max
Returns the maximum of two values
*/
#[doc = "Returns the maximum of two values"]
pure fn max<T: copy>(x: T, y: T) -> T { if x < y { y } else { x } }
#[test]

View File

@ -1,107 +1,83 @@
/*
Module: option
#[doc = "
Operations on the ubiquitous `option` type.
Represents the presence or absence of a value.
Type `option` represents an optional value.
Every option<T> value can either be some(T) or none. Where in other languages
you might use a nullable type, in Rust you would use an option type.
*/
Every `option<T>` value can either be `some(T)` or `none`. Where in other
languages you might use a nullable type, in Rust you would use an option type.
"];
/*
Tag: t
The option type
*/
#[doc = "The option type"]
enum t<T> {
/* Variant: none */
none,
/* Variant: some */
some(T),
}
/* Section: Operations */
/*
Function: get
Gets the value out of an option
Failure:
Fails if the value equals `none`.
*/
pure fn get<T: copy>(opt: t<T>) -> T {
#[doc = "
Gets the value out of an option
# Failure
Fails if the value equals `none`
"];
alt opt { some(x) { ret x; } none { fail "option none"; } }
}
/*
*/
fn map<T, U: copy>(opt: t<T>, f: fn(T) -> U) -> t<U> {
#[doc = "Maps a `some` value from one type to another"];
alt opt { some(x) { some(f(x)) } none { none } }
}
/*
Function: chain
Update an optional value by optionally running its content through a function
that returns an option.
*/
fn chain<T, U>(opt: t<T>, f: fn(T) -> t<U>) -> t<U> {
#[doc = "
Update an optional value by optionally running its content through a
function that returns an option.
"];
alt opt { some(x) { f(x) } none { none } }
}
/*
Function: is_none
Returns true if the option equals none
*/
pure fn is_none<T>(opt: t<T>) -> bool {
#[doc = "Returns true if the option equals `none`"];
alt opt { none { true } some(_) { false } }
}
/*
Function: is_some
pure fn is_some<T>(opt: t<T>) -> bool {
#[doc = "Returns true if the option contains some value"];
Returns true if the option contains some value
*/
pure fn is_some<T>(opt: t<T>) -> bool { !is_none(opt) }
!is_none(opt)
}
/*
Function: from_maybe
Returns the contained value or a default
*/
pure fn from_maybe<T: copy>(def: T, opt: t<T>) -> T {
#[doc = "Returns the contained value or a default"];
alt opt { some(x) { x } none { def } }
}
/*
Function: maybe
Applies a function to the contained value or returns a default
*/
fn maybe<T, U: copy>(def: U, opt: t<T>, f: fn(T) -> U) -> U {
#[doc = "Applies a function to the contained value or returns a default"];
alt opt { none { def } some(t) { f(t) } }
}
// FIXME: Can be defined in terms of the above when/if we have const bind.
/*
Function: may
Performs an operation on the contained value or does nothing
*/
fn may<T>(opt: t<T>, f: fn(T)) {
alt opt { none {/* nothing */ } some(t) { f(t); } }
#[doc = "Performs an operation on the contained value or does nothing"];
alt opt { none { } some(t) { f(t); } }
}
/*
Function: unwrap
Moves a value out of an option type and returns it. Useful primarily
for getting strings, vectors and unique pointers out of option types
without copying them.
*/
fn unwrap<T>(-opt: t<T>) -> T unsafe {
#[doc = "
Moves a value out of an option type and returns it.
Useful primarily for getting strings, vectors and unique pointers out of
option types without copying them.
"];
let addr = alt opt {
some(x) { ptr::addr_of(x) }
none { fail "option none" }

View File

@ -1,18 +1,20 @@
// Higher-level interfaces to libc::* functions and operating system services.
//
// In general these take and return rust types, use rust idioms (enums,
// closures, vectors) rather than C idioms, and do more extensive safety
// checks.
//
// This module is not meant to only contain 1:1 mappings to libc entries; any
// os-interface code that is reasonably useful and broadly applicable can go
// here. Including utility routines that merely build on other os code.
//
// We assume the general case is that users do not care, and do not want to
// be made to care, which operating system they are on. While they may want
// to special case various special cases -- and so we will not _hide_ the
// facts of which OS the user is on -- they should be given the opportunity
// to write OS-ignorant code by default.
#[doc = "
Higher-level interfaces to libc::* functions and operating system services.
In general these take and return rust types, use rust idioms (enums,
closures, vectors) rather than C idioms, and do more extensive safety
checks.
This module is not meant to only contain 1:1 mappings to libc entries; any
os-interface code that is reasonably useful and broadly applicable can go
here. Including utility routines that merely build on other os code.
We assume the general case is that users do not care, and do not want to
be made to care, which operating system they are on. While they may want
to special case various special cases -- and so we will not _hide_ the
facts of which OS the user is on -- they should be given the opportunity
to write OS-ignorant code by default.
"];
import libc::{c_char, c_void, c_int, c_uint, size_t, ssize_t,
mode_t, pid_t, FILE};
@ -327,21 +329,19 @@ fn self_exe_path() -> option<path> {
}
/*
Function: homedir
#[doc = "
Returns the path to the user's home directory, if known.
On Unix, returns the value of the "HOME" environment variable if it is set and
On Unix, returns the value of the 'HOME' environment variable if it is set and
not equal to the empty string.
On Windows, returns the value of the "HOME" environment variable if it is set
On Windows, returns the value of the 'HOME' environment variable if it is set
and not equal to the empty string. Otherwise, returns the value of the
"USERPROFILE" environment variable if it is set and not equal to the empty
'USERPROFILE' environment variable if it is set and not equal to the empty
string.
Otherwise, homedir returns option::none.
*/
"]
fn homedir() -> option<path> {
ret alt getenv("HOME") {
some(p) {
@ -377,22 +377,14 @@ fn homedir() -> option<path> {
/*
Function: path_is_dir
Indicates whether a path represents a directory.
*/
#[doc = "Indicates whether a path represents a directory"]
fn path_is_dir(p: path) -> bool {
str::as_buf(p) {|buf|
rustrt::rust_path_is_dir(buf) != 0 as c_int
}
}
/*
Function: path_exists
Indicates whether a path exists.
*/
#[doc = "Indicates whether a path exists"]
fn path_exists(p: path) -> bool {
str::as_buf(p) {|buf|
rustrt::rust_path_exists(buf) != 0 as c_int
@ -401,15 +393,13 @@ fn path_exists(p: path) -> bool {
// FIXME: under Windows, we should prepend the current drive letter to paths
// that start with a slash.
/*
Function: make_absolute
#[doc = "
Convert a relative path to an absolute path
If the given path is relative, return it prepended with the current working
directory. If the given path is already an absolute path, return it
as is.
*/
"]
// NB: this is here rather than in path because it is a form of environment
// querying; what it does depends on the process working directory, not just
// the input paths.
@ -422,11 +412,7 @@ fn make_absolute(p: path) -> path {
}
/*
Function: make_dir
Creates a directory at the specified path.
*/
#[doc = "Creates a directory at the specified path"]
fn make_dir(p: path, mode: c_int) -> bool {
ret mkdir(p, mode);
@ -453,11 +439,7 @@ fn make_dir(p: path, mode: c_int) -> bool {
}
}
/*
Function: list_dir
Lists the contents of a directory.
*/
#[doc = "Lists the contents of a directory"]
fn list_dir(p: path) -> [str] {
#[cfg(target_os = "linux")]
@ -485,11 +467,7 @@ fn list_dir(p: path) -> [str] {
ret full_paths;
}
/*
Function: remove_dir
Removes a directory at the specified path.
*/
#[doc = "Removes a directory at the specified path"]
fn remove_dir(p: path) -> bool {
ret rmdir(p);
@ -538,11 +516,7 @@ fn change_dir(p: path) -> bool {
}
}
/*
Function: remove_file
Deletes an existing file.
*/
#[doc = "Deletes an existing file"]
fn remove_file(p: path) -> bool {
ret unlink(p);

View File

@ -1,8 +1,4 @@
/*
Module: path
Path data type and helper functions.
*/
#[doc = "Path data type and helper functions"]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
@ -18,14 +14,12 @@ mod consts {
const alt_path_sep: char = '\\';
}
/*
Function: path_is_absolute
#[doc = "
Indicates whether a path is absolute.
A path is considered absolute if it begins at the filesystem root ("/") or,
A path is considered absolute if it begins at the filesystem root (\"/\") or,
on Windows, begins with a drive letter.
*/
"]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "linux")]
@ -43,19 +37,11 @@ fn path_is_absolute(p: str) -> bool {
/*
Function: path_sep
Get the default path separator for the host platform
*/
#[doc = "Get the default path separator for the host platform"]
fn path_sep() -> str { ret str::from_char(consts::path_sep); }
// FIXME: This type should probably be constrained
/*
Type: path
A path or fragment of a filesystem path
*/
#[doc = "A path or fragment of a filesystem path"]
type path = str;
fn split_dirname_basename (pp: path) -> {dirname: str, basename: str} {
@ -70,47 +56,40 @@ fn split_dirname_basename (pp: path) -> {dirname: str, basename: str} {
}
}
/*
Function: dirname
#[doc = "
Get the directory portion of a path
Returns all of the path up to, but excluding, the final path separator.
The dirname of "/usr/share" will be "/usr", but the dirname of
"/usr/share/" is "/usr/share".
The dirname of \"/usr/share\" will be \"/usr\", but the dirname of
\"/usr/share/\" is \"/usr/share\".
If the path is not prefixed with a directory, then "." is returned.
*/
If the path is not prefixed with a directory, then \".\" is returned.
"]
fn dirname(pp: path) -> path {
ret split_dirname_basename(pp).dirname;
}
/*
Function: basename
#[doc = "
Get the file name portion of a path
Returns the portion of the path after the final path separator.
The basename of "/usr/share" will be "share". If there are no
The basename of \"/usr/share\" will be \"share\". If there are no
path separators in the path then the returned path is identical to
the provided path. If an empty path is provided or the path ends
with a path separator then an empty path is returned.
*/
"]
fn basename(pp: path) -> path {
ret split_dirname_basename(pp).basename;
}
// FIXME: Need some typestate to avoid bounds check when len(pre) == 0
/*
Function: connect
#[doc = "
Connects to path segments
Given paths `pre` and `post, removes any trailing path separator on `pre` and
any leading path separator on `post`, and returns the concatenation of the two
with a single path separator between them.
*/
"]
fn connect(pre: path, post: path) -> path unsafe {
let mut pre_ = pre;
let mut post_ = post;
@ -122,13 +101,11 @@ fn connect(pre: path, post: path) -> path unsafe {
ret pre_ + path_sep() + post_;
}
/*
Function: connect_many
#[doc = "
Connects a vector of path segments into a single path.
Inserts path separators as needed.
*/
"]
fn connect_many(paths: [path]) -> path {
ret if vec::len(paths) == 1u {
paths[0]
@ -138,31 +115,29 @@ fn connect_many(paths: [path]) -> path {
}
}
/*
Function: split
#[doc = "
Split a path into it's individual components
Splits a given path by path separators and returns a vector containing
each piece of the path. On Windows, if the path is absolute then
the first element of the returned vector will be the drive letter
followed by a colon.
*/
"]
fn split(p: path) -> [path] {
str::split_nonempty(p, {|c|
c == consts::path_sep || c == consts::alt_path_sep
})
}
/*
Function: splitext
#[doc = "
Split a path into the part before the extension and the extension
Split a path into a pair of strings with the first element being the filename
without the extension and the second being either empty or the file extension
including the period. Leading periods in the basename are ignored. If the
path includes directory components then they are included in the filename part
of the result pair.
*/
"]
fn splitext(p: path) -> (str, str) {
if str::is_empty(p) { ("", "") }
else {
@ -204,13 +179,11 @@ fn splitext(p: path) -> (str, str) {
}
}
/*
Function: normalize
Removes extra "." and ".." entries from paths.
#[doc = "
Removes extra '.' and '..' entries from paths
Does not follow symbolic links.
*/
"]
fn normalize(p: path) -> path {
let s = split(p);
let s = strip_dots(s);

View File

@ -1,8 +1,5 @@
/*
Module: ptr
#[doc = "Unsafe pointer utility functions"]
Unsafe pointer utility functions
*/
#[abi = "rust-intrinsic"]
native mod rusti {
fn addr_of<T>(val: T) -> *T;
@ -11,70 +8,50 @@ native mod rusti {
fn memmove<T>(dst: *T, src: *T, count: ctypes::uintptr_t);
}
/*
Function: addr_of
Get an unsafe pointer to a value
*/
#[doc = "Get an unsafe pointer to a value"]
#[inline(always)]
fn addr_of<T>(val: T) -> *T { ret rusti::addr_of(val); }
/*
Function: mut_addr_of
Get an unsafe mutable pointer to a value
*/
#[doc = "Get an unsafe mutable pointer to a value"]
#[inline(always)]
fn mut_addr_of<T>(val: T) -> *mutable T unsafe {
ret unsafe::reinterpret_cast(rusti::addr_of(val));
}
/*
Function: offset
Calculate the offset from a pointer
*/
#[doc = "Calculate the offset from a pointer"]
#[inline(always)]
fn offset<T>(ptr: *T, count: uint) -> *T {
ret rusti::ptr_offset(ptr, count);
}
/*
Function: mut_offset
Calculate the offset from a mutable pointer
*/
#[doc = "Calculate the offset from a mutable pointer"]
#[inline(always)]
fn mut_offset<T>(ptr: *mutable T, count: uint) -> *mutable T {
ret rusti::ptr_offset(ptr as *T, count) as *mutable T;
}
/*
Function: null
Create an unsafe null pointer
*/
#[doc = "Create an unsafe null pointer"]
#[inline(always)]
fn null<T>() -> *T unsafe { ret unsafe::reinterpret_cast(0u); }
/*
Function: memcpy
#[doc = "
Copies data from one location to another
Copies data from one src to dst that is not overlapping each other.
Count is the number of elements to copy and not the number of bytes.
*/
Copies `count` elements (not bytes) from `src` to `dst`. The source
and destination may not overlap.
"]
#[inline(always)]
unsafe fn memcpy<T>(dst: *T, src: *T, count: uint) {
rusti::memcpy(dst, src, count);
}
/*
Function: memmove
#[doc = "
Copies data from one location to another
Copies data from one src to dst, overlap between the two pointers may occur.
Count is the number of elements to copy and not the number of bytes.
*/
Copies `count` elements (not bytes) from `src` to `dst`. The source
and destination may overlap.
"]
#[inline(always)]
unsafe fn memmove<T>(dst: *T, src: *T, count: uint) {
rusti::memmove(dst, src, count);

View File

@ -1,42 +1,20 @@
/*
Module: result
#[doc = "A type representing either success or failure"];
A type representing either success or failure
*/
/* Section: Types */
/*
Tag: t
The result type
*/
#[doc = "The result type"]
enum t<T, U> {
/*
Variant: ok
Contains the result value
*/
#[doc = "Contains the successful result value"]
ok(T),
/*
Variant: err
Contains the error value
*/
#[doc = "Contains the error value"]
err(U)
}
/* Section: Operations */
/*
Function: get
#[doc = "
Get the value out of a successful result
Failure:
# Failure
If the result is an error
*/
"]
fn get<T: copy, U>(res: t<T, U>) -> T {
alt res {
ok(t) { t }
@ -48,15 +26,13 @@ fn get<T: copy, U>(res: t<T, U>) -> T {
}
}
/*
Function: get_err
#[doc = "
Get the value out of an error result
Failure:
# Failure
If the result is not an error
*/
"]
fn get_err<T, U: copy>(res: t<T, U>) -> U {
alt res {
err(u) { u }
@ -66,11 +42,7 @@ fn get_err<T, U: copy>(res: t<T, U>) -> U {
}
}
/*
Function: success
Returns true if the result is <ok>
*/
#[doc = "Returns true if the result is `ok`"]
pure fn success<T, U>(res: t<T, U>) -> bool {
alt res {
ok(_) { true }
@ -78,15 +50,17 @@ pure fn success<T, U>(res: t<T, U>) -> bool {
}
}
/*
Function: failure
Returns true if the result is <error>
*/
#[doc = "Returns true if the result is `error`"]
pure fn failure<T, U>(res: t<T, U>) -> bool {
!success(res)
}
#[doc = "
Convert to the `either` type
`ok` result variants are converted to `either::right` variants, `err`
result variants are converted to `either::left`.
"]
pure fn to_either<T: copy, U: copy>(res: t<U, T>) -> either::t<T, U> {
alt res {
ok(res) { either::right(res) }
@ -94,22 +68,19 @@ pure fn to_either<T: copy, U: copy>(res: t<U, T>) -> either::t<T, U> {
}
}
/*
Function: chain
#[doc = "
Call a function based on a previous result
If `res` is <ok> then the value is extracted and passed to `op` whereupon
`op`s result is returned. if `res` is <err> then it is immediately returned.
If `res` is `ok` then the value is extracted and passed to `op` whereupon
`op`s result is returned. if `res` is `err` then it is immediately returned.
This function can be used to compose the results of two functions.
Example:
> let res = chain(read_file(file), { |buf|
> ok(parse_buf(buf))
> })
*/
let res = chain(read_file(file)) { |buf|
ok(parse_buf(buf))
}
"]
fn chain<T, U: copy, V: copy>(res: t<T, V>, op: fn(T) -> t<U, V>)
-> t<U, V> {
alt res {

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,5 @@
/*
Module: sys
#[doc = "Misc low level stuff"]
Misc low level stuff
*/
enum type_desc = {
first_param: **ctypes::c_int,
size: ctypes::size_t,
@ -31,48 +28,32 @@ native mod rusti {
fn frame_address(n: ctypes::c_uint) -> ctypes::uintptr_t;
}
/*
Function: get_type_desc
#[doc = "
Returns a pointer to a type descriptor.
Returns a pointer to a type descriptor. Useful for calling certain
function in the Rust runtime or otherwise performing dark magick.
*/
Useful for calling certain function in the Rust runtime or otherwise
performing dark magick.
"]
fn get_type_desc<T>() -> *type_desc {
ret rusti::get_type_desc::<T>();
}
/*
Function: last_os_error
Get a string representing the platform-dependent last error
*/
#[doc = "Get a string representing the platform-dependent last error"]
fn last_os_error() -> str {
rustrt::last_os_error()
}
/*
Function: size_of
Returns the size of a type
*/
#[doc = "Returns the size of a type"]
fn size_of<T>() -> uint unsafe {
ret (*get_type_desc::<T>()).size;
}
/*
Function: align_of
Returns the alignment of a type
*/
#[doc = "Returns the alignment of a type"]
fn align_of<T>() -> uint unsafe {
ret (*get_type_desc::<T>()).align;
}
/*
Function: refcount
Returns the refcount of a shared box
*/
#[doc = "Returns the refcount of a shared box"]
fn refcount<T>(t: @T) -> uint {
ret rustrt::refcount::<T>(t);
}
@ -81,14 +62,14 @@ fn log_str<T>(t: T) -> str {
rustrt::shape_log_str(get_type_desc::<T>(), t)
}
#[doc(
brief = "Sets the process exit code",
desc = "Sets the exit code returned by the process if all supervised \
tasks terminate successfully (without failing). If the current \
root task fails and is supervised by the scheduler then any \
user-specified exit status is ignored and the process exits \
with the default failure status."
)]
#[doc = "
Sets the process exit code
Sets the exit code returned by the process if all supervised tasks terminate
successfully (without failing). If the current root task fails and is
supervised by the scheduler then any user-specified exit status is ignored and
the process exits with the default failure status
"]
fn set_exit_status(code: int) {
rustrt::rust_set_exit_status(code as ctypes::intptr_t);
}

View File

@ -1,5 +1,4 @@
#[doc = "
Task management.
An executing Rust program consists of a tree of tasks, each with their own
@ -14,12 +13,13 @@ process.
Tasks may execute in parallel and are scheduled automatically by the runtime.
Example:
spawn {||
log(error, \"Hello, World!\");
}
# Example
~~~
spawn {||
log(error, \"Hello, World!\");
}
~~~
"];
export task;
@ -58,7 +58,6 @@ export get_task;
enum task = task_id;
#[doc = "
Indicates the manner in which a task exited.
A task that completes without failing and whose supervised children complete
@ -66,18 +65,13 @@ without failing is considered to exit successfully.
FIXME: This description does not indicate the current behavior for linked
failure.
"]
enum task_result {
success,
failure,
}
#[doc = "
A message type for notifying of task lifecycle events
"]
#[doc = "A message type for notifying of task lifecycle events"]
enum notification {
#[doc = "Sent when a task exits with the task handle and result"]
exit(task, task_result)
@ -96,10 +90,9 @@ enum sched_mode {
}
#[doc = "
Scheduler configuration options
Fields:
# Fields
* sched_mode - The operating mode of the scheduler
@ -110,7 +103,6 @@ Fields:
appropriate for running code written in languages like C. By default these
native stacks have unspecified size, but with this option their size can
be precisely specified.
"]
type sched_opts = {
mode: sched_mode,
@ -118,10 +110,9 @@ type sched_opts = {
};
#[doc = "
Task configuration options
Fields:
# Fields
* supervise - Do not propagate failure to the parent task
@ -152,11 +143,9 @@ type task_opts = {
};
#[doc = "
The task builder type.
Provides detailed control over the properties and behavior of new tasks.
"]
// NB: Builders are designed to be single-use because they do stateful
// things that get weird when reusing - e.g. if you create a result future
@ -176,12 +165,10 @@ enum task_builder = {
fn default_task_opts() -> task_opts {
#[doc = "
The default task options
By default all tasks are supervised by their parent, are spawned
into the same scheduler, and do not post lifecycle notifications.
"];
{
@ -211,7 +198,6 @@ fn get_opts(builder: task_builder) -> task_opts {
fn set_opts(builder: task_builder, opts: task_opts) {
#[doc = "
Set the task_opts associated with a task_builder
To update a single option use a pattern like the following:
@ -220,7 +206,6 @@ fn set_opts(builder: task_builder, opts: task_opts) {
supervise: false
with get_opts(builder)
});
"];
builder.opts = opts;
@ -228,7 +213,6 @@ fn set_opts(builder: task_builder, opts: task_opts) {
fn add_wrapper(builder: task_builder, gen_body: fn@(+fn~()) -> fn~()) {
#[doc = "
Add a wrapper to the body of the spawned task.
Before the task is spawned it is passed through a 'body generator'
@ -239,7 +223,6 @@ fn add_wrapper(builder: task_builder, gen_body: fn@(+fn~()) -> fn~()) {
This function augments the current body generator with a new body
generator by applying the task body which results from the
existing body generator to the new body generator.
"];
let prev_gen_body = builder.gen_body;
@ -249,20 +232,18 @@ fn add_wrapper(builder: task_builder, gen_body: fn@(+fn~()) -> fn~()) {
}
fn run(-builder: task_builder, +f: fn~()) {
#[doc(desc = "
#[doc = "
Creates and exucutes a new child task
Sets up a new task with its own call stack and schedules it to run
the provided unique closure. The task has the properties and behavior
specified by `builder`.
", failure = "
# Failure
When spawning into a new scheduler, the number of threads requested
must be greater than zero.
")];
"];
let body = builder.gen_body(f);
spawn_raw(builder.opts, body);
@ -273,7 +254,6 @@ fn run(-builder: task_builder, +f: fn~()) {
fn future_result(builder: task_builder) -> future::future<task_result> {
#[doc = "
Get a future representing the exit status of the task.
Taking the value of the future will block until the child task terminates.
@ -283,7 +263,6 @@ fn future_result(builder: task_builder) -> future::future<task_result> {
builder. If additional tasks are spawned with the same builder
then a new result future must be obtained prior to spawning each
task.
"];
// FIXME (1087, 1857): Once linked failure and notification are
@ -332,7 +311,6 @@ fn unsupervise(builder: task_builder) {
fn run_listener<A:send>(-builder: task_builder,
+f: fn~(comm::port<A>)) -> comm::chan<A> {
#[doc = "
Runs a new task while providing a channel from the parent to the child
Sets up a communication channel from the current task to the new
@ -362,7 +340,6 @@ fn run_listener<A:send>(-builder: task_builder,
fn spawn(+f: fn~()) {
#[doc = "
Creates and exucutes a new child task
Sets up a new task with its own call stack and schedules it to run
@ -376,7 +353,6 @@ fn spawn(+f: fn~()) {
fn spawn_listener<A:send>(+f: fn~(comm::port<A>)) -> comm::chan<A> {
#[doc = "
Runs a new task while providing a channel from the parent to the child
Sets up a communication channel from the current task to the new
@ -399,27 +375,24 @@ fn spawn_listener<A:send>(+f: fn~(comm::port<A>)) -> comm::chan<A> {
// Likewise, the parent has both a 'po' and 'ch'
This function is equivalent to `run_listener(mk_task_builder(), f)`.
"];
run_listener(mk_task_builder(), f)
}
fn spawn_sched(mode: sched_mode, +f: fn~()) {
#[doc(desc = "
#[doc = "
Creates a new scheduler and executes a task on it
Tasks subsequently spawned by that task will also execute on
the new scheduler. When there are no more tasks to execute the
scheduler terminates.
", failure = "
# Failure
In manual threads mode the number of threads requested must be
greater than zero.
")];
"];
let mut builder = mk_task_builder();
set_opts(builder, {
@ -433,18 +406,16 @@ fn spawn_sched(mode: sched_mode, +f: fn~()) {
}
fn try<T:send>(+f: fn~() -> T) -> result::t<T,()> {
#[doc(desc = "
#[doc = "
Execute a function in another task and return either the return value
of the function or result::err.
", return = "
# Return value
If the function executed successfully then try returns result::ok
containing the value returned by the function. If the function fails
then try returns result::err containing nil.
")];
"];
let po = comm::port();
let ch = comm::chan(po);

View File

@ -1,7 +1,3 @@
/*
Module: tuple
*/
fn first<T:copy, U:copy>(pair: (T, U)) -> T {
let (t, _) = pair;
ret t;

View File

@ -1,64 +1,25 @@
#[doc = "Operations and constants for `u32`"];
/*
Module: u32
*/
/*
Const: min_value
Return the minimal value for a u32
*/
const min_value: u32 = 0u32;
/*
Const: max_value
Return the maximal value for a u32
*/
const max_value: u32 = 0u32 - 1u32;
pure fn min(x: u32, y: u32) -> u32 { if x < y { x } else { y } }
pure fn max(x: u32, y: u32) -> u32 { if x > y { x } else { y } }
/* Function: add */
pure fn add(x: u32, y: u32) -> u32 { ret x + y; }
/* Function: sub */
pure fn sub(x: u32, y: u32) -> u32 { ret x - y; }
/* Function: mul */
pure fn mul(x: u32, y: u32) -> u32 { ret x * y; }
/* Function: div */
pure fn div(x: u32, y: u32) -> u32 { ret x / y; }
/* Function: rem */
pure fn rem(x: u32, y: u32) -> u32 { ret x % y; }
/* Predicate: lt */
pure fn lt(x: u32, y: u32) -> bool { ret x < y; }
/* Predicate: le */
pure fn le(x: u32, y: u32) -> bool { ret x <= y; }
/* Predicate: eq */
pure fn eq(x: u32, y: u32) -> bool { ret x == y; }
/* Predicate: ne */
pure fn ne(x: u32, y: u32) -> bool { ret x != y; }
/* Predicate: ge */
pure fn ge(x: u32, y: u32) -> bool { ret x >= y; }
/* Predicate: gt */
pure fn gt(x: u32, y: u32) -> bool { ret x > y; }
/*
Function: range
Iterate over the range [`lo`..`hi`)
*/
#[doc = "Iterate over the range [`lo`..`hi`)"]
fn range(lo: u32, hi: u32, it: fn(u32)) {
let mut i = lo;
while i < hi { it(i); i += 1u32; }

View File

@ -1,74 +1,31 @@
#[doc = "Operations and constants for `u64`"];
/*
Module: u64
*/
/*
Const: min_value
Return the minimal value for a u64
*/
const min_value: u64 = 0u64;
/*
Const: max_value
Return the maximal value for a u64
*/
const max_value: u64 = 0u64 - 1u64;
pure fn min(x: u64, y: u64) -> u64 { if x < y { x } else { y } }
pure fn max(x: u64, y: u64) -> u64 { if x > y { x } else { y } }
/* Function: add */
pure fn add(x: u64, y: u64) -> u64 { ret x + y; }
/* Function: sub */
pure fn sub(x: u64, y: u64) -> u64 { ret x - y; }
/* Function: mul */
pure fn mul(x: u64, y: u64) -> u64 { ret x * y; }
/* Function: div */
pure fn div(x: u64, y: u64) -> u64 { ret x / y; }
/* Function: rem */
pure fn rem(x: u64, y: u64) -> u64 { ret x % y; }
/* Predicate: lt */
pure fn lt(x: u64, y: u64) -> bool { ret x < y; }
/* Predicate: le */
pure fn le(x: u64, y: u64) -> bool { ret x <= y; }
/* Predicate: eq */
pure fn eq(x: u64, y: u64) -> bool { ret x == y; }
/* Predicate: ne */
pure fn ne(x: u64, y: u64) -> bool { ret x != y; }
/* Predicate: ge */
pure fn ge(x: u64, y: u64) -> bool { ret x >= y; }
/* Predicate: gt */
pure fn gt(x: u64, y: u64) -> bool { ret x > y; }
/*
Function: range
Iterate over the range [`lo`..`hi`)
*/
#[doc = "Iterate over the range [`lo`..`hi`)"]
fn range(lo: u64, hi: u64, it: fn(u64)) {
let mut i = lo;
while i < hi { it(i); i += 1u64; }
}
/*
Function: to_str
Convert to a string in a given base
*/
#[doc = "Convert to a string in a given base"]
fn to_str(n: u64, radix: uint) -> str {
assert (0u < radix && radix <= 16u);
@ -105,18 +62,10 @@ fn to_str(n: u64, radix: uint) -> str {
ret s;
}
/*
Function: str
Convert to a string
*/
#[doc = "Convert to a string"]
fn str(n: u64) -> str { ret to_str(n, 10u); }
/*
Function: from_str
Parse a string as an unsigned integer.
*/
#[doc = "Parse a string as an unsigned integer."]
fn from_str(buf: str, radix: u64) -> option<u64> {
if str::len(buf) == 0u { ret none; }
let mut i = str::len(buf) - 1u;

View File

@ -1,64 +1,27 @@
#[doc = "Operations and constants for `u8`"];
/*
Module: u8
*/
/*
Const: min_value
The minumum value of a u8.
*/
const min_value: u8 = 0u8;
/*
Const: max_value
The maximum value of a u8.
*/
const max_value: u8 = 0u8 - 1u8;
/* Function: add */
pure fn min(x: u8, y: u8) -> u8 { if x < y { x } else { y } }
pure fn max(x: u8, y: u8) -> u8 { if x > y { x } else { y } }
pure fn add(x: u8, y: u8) -> u8 { ret x + y; }
/* Function: sub */
pure fn sub(x: u8, y: u8) -> u8 { ret x - y; }
/* Function: mul */
pure fn mul(x: u8, y: u8) -> u8 { ret x * y; }
/* Function: div */
pure fn div(x: u8, y: u8) -> u8 { ret x / y; }
/* Function: rem */
pure fn rem(x: u8, y: u8) -> u8 { ret x % y; }
/* Predicate: lt */
pure fn lt(x: u8, y: u8) -> bool { ret x < y; }
/* Predicate: le */
pure fn le(x: u8, y: u8) -> bool { ret x <= y; }
/* Predicate: eq */
pure fn eq(x: u8, y: u8) -> bool { ret x == y; }
/* Predicate: ne */
pure fn ne(x: u8, y: u8) -> bool { ret x != y; }
/* Predicate: ge */
pure fn ge(x: u8, y: u8) -> bool { ret x >= y; }
/* Predicate: gt */
pure fn gt(x: u8, y: u8) -> bool { ret x > y; }
/* Predicate: is_ascii */
pure fn is_ascii(x: u8) -> bool { ret 0u8 == x & 128u8; }
/*
Function: range
Iterate over the range [`lo`..`hi`)
*/
#[doc = "Iterate over the range [`lo`..`hi`)"]
fn range(lo: u8, hi: u8, it: fn(u8)) {
let mut i = lo;
while i < hi { it(i); i += 1u8; }

View File

@ -1,158 +1,103 @@
#[doc = "Operations and constants for `uint`"];
/*
Module: uint
*/
/*
Const: min_value
Return the minimal value for an uint.
This is always 0
*/
const min_value: uint = 0u;
/*
Const: max_value
Return the maximal value for an uint.
This is 2^wordsize - 1
*/
const max_value: uint = 0u - 1u;
/*
Function: min
*/
pure fn min(x: uint, y: uint) -> uint {
if x < y { x } else { y }
}
pure fn min(x: uint, y: uint) -> uint { if x < y { x } else { y } }
pure fn max(x: uint, y: uint) -> uint { if x > y { x } else { y } }
/*
Function: max
*/
pure fn max(x: uint, y: uint) -> uint {
if x > y { x } else { y }
}
/* Function: add */
pure fn add(x: uint, y: uint) -> uint { ret x + y; }
/* Function: sub */
pure fn sub(x: uint, y: uint) -> uint { ret x - y; }
/* Function: mul */
pure fn mul(x: uint, y: uint) -> uint { ret x * y; }
/* Function: div */
pure fn div(x: uint, y: uint) -> uint { ret x / y; }
/* Function: div_ceil
pure fn rem(x: uint, y: uint) -> uint { ret x % y; }
pure fn lt(x: uint, y: uint) -> bool { ret x < y; }
pure fn le(x: uint, y: uint) -> bool { ret x <= y; }
pure fn eq(x: uint, y: uint) -> bool { ret x == y; }
pure fn ne(x: uint, y: uint) -> bool { ret x != y; }
pure fn ge(x: uint, y: uint) -> bool { ret x >= y; }
pure fn gt(x: uint, y: uint) -> bool { ret x > y; }
Divide two numbers, return the result, rounded up.
Parameters:
x - an integer
y - an integer distinct from 0u
#[doc = "
Divide two numbers, return the result, rounded up.
Return:
The smallest integer `q` such that `x/y <= q`.
*/
# Arguments
* x - an integer
* y - an integer distinct from 0u
# Return value
The smallest integer `q` such that `x/y <= q`.
"]
pure fn div_ceil(x: uint, y: uint) -> uint {
let div = div(x, y);
if x % y == 0u { ret div;}
else { ret div + 1u; }
}
/* Function: div_ceil
#[doc = "
Divide two numbers, return the result, rounded to the closest integer.
Divide two numbers, return the result, rounded to the closest integer.
# Arguments
Parameters:
x - an integer
y - an integer distinct from 0u
* x - an integer
* y - an integer distinct from 0u
Return:
The integer `q` closest to `x/y`.
*/
# Return value
The integer `q` closest to `x/y`.
"]
pure fn div_round(x: uint, y: uint) -> uint {
let div = div(x, y);
if x % y * 2u < y { ret div;}
else { ret div + 1u; }
}
/* Function: div_ceil
#[doc = "
Divide two numbers, return the result, rounded down.
Divide two numbers, return the result, rounded down.
Note: This is the same function as `div`.
Parameters:
x - an integer
y - an integer distinct from 0u
# Arguments
Note: This is the same function as `div`.
* x - an integer
* y - an integer distinct from 0u
Return:
The smallest integer `q` such that `x/y <= q`. This
is either `x/y` or `x/y + 1`.
*/
# Return value
The smallest integer `q` such that `x/y <= q`. This
is either `x/y` or `x/y + 1`.
"]
pure fn div_floor(x: uint, y: uint) -> uint { ret x / y; }
/* Function: rem */
pure fn rem(x: uint, y: uint) -> uint { ret x % y; }
/* Predicate: lt */
pure fn lt(x: uint, y: uint) -> bool { ret x < y; }
/* Predicate: le */
pure fn le(x: uint, y: uint) -> bool { ret x <= y; }
/* Predicate: eq */
pure fn eq(x: uint, y: uint) -> bool { ret x == y; }
/* Predicate: ne */
pure fn ne(x: uint, y: uint) -> bool { ret x != y; }
/* Predicate: ge */
pure fn ge(x: uint, y: uint) -> bool { ret x >= y; }
/* Predicate: gt */
pure fn gt(x: uint, y: uint) -> bool { ret x > y; }
/*
Function: hash
Produce a uint suitable for use in a hash table
*/
#[doc = "Produce a uint suitable for use in a hash table"]
fn hash(x: uint) -> uint { ret x; }
/*
Function: range
Iterate over the range [`lo`..`hi`)
*/
#[doc = "Iterate over the range [`lo`..`hi`)"]
#[inline(always)]
fn range(lo: uint, hi: uint, it: fn(uint)) {
let mut i = lo;
while i < hi { it(i); i += 1u; }
}
/*
Function: iterate
#[doc = "
Iterate over the range [`lo`..`hi`), or stop when requested
Parameters:
lo - The integer at which to start the loop (included)
hi - The integer at which to stop the loop (excluded)
it - A block to execute with each consecutive integer of the range.
Return `true` to continue, `false` to stop.
# Arguments
Returns:
* lo - The integer at which to start the loop (included)
* hi - The integer at which to stop the loop (excluded)
* it - A block to execute with each consecutive integer of the range.
Return `true` to continue, `false` to stop.
# Return value
`true` If execution proceeded correctly, `false` if it was interrupted,
that is if `it` returned `false` at any point.
*/
"]
fn iterate(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool {
let mut i = lo;
while i < hi {
@ -162,11 +107,7 @@ fn iterate(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool {
ret true;
}
/*
Function: next_power_of_two
Returns the smallest power of 2 greater than or equal to `n`
*/
#[doc = "Returns the smallest power of 2 greater than or equal to `n`"]
fn next_power_of_two(n: uint) -> uint {
let halfbits: uint = sys::size_of::<uint>() * 4u;
let mut tmp: uint = n - 1u;
@ -175,20 +116,18 @@ fn next_power_of_two(n: uint) -> uint {
ret tmp + 1u;
}
/*
Function: parse_buf
#[doc = "
Parse a buffer of bytes
Parameters:
# Arguments
buf - A byte buffer
radix - The base of the number
* buf - A byte buffer
* radix - The base of the number
Failure:
# Failure
buf must not be empty
*/
`buf` must not be empty
"]
fn parse_buf(buf: [u8], radix: uint) -> option<uint> {
if vec::len(buf) == 0u { ret none; }
let mut i = vec::len(buf) - 1u;
@ -206,18 +145,10 @@ fn parse_buf(buf: [u8], radix: uint) -> option<uint> {
fail;
}
/*
Function: from_str
Parse a string to an int
*/
#[doc = "Parse a string to an int"]
fn from_str(s: str) -> option<uint> { parse_buf(str::bytes(s), 10u) }
/*
Function: to_str
Convert to a string in a given base
*/
#[doc = "Convert to a string in a given base"]
fn to_str(num: uint, radix: uint) -> str {
let mut n = num;
assert (0u < radix && radix <= 16u);
@ -254,18 +185,10 @@ fn to_str(num: uint, radix: uint) -> str {
ret s1;
}
/*
Function: str
Convert to a string
*/
#[doc = "Convert to a string"]
fn str(i: uint) -> str { ret to_str(i, 10u); }
/*
Function: compl
Computes the bitwise complement.
*/
#[doc = "Computes the bitwise complement"]
fn compl(i: uint) -> uint {
max_value ^ i
}

View File

@ -2565,6 +2565,7 @@ mod general_category {
}
mod derived_property {
#[doc = "Check if a character has the alphabetic unicode property"]
pure fn Alphabetic(c: char) -> bool {
ret alt c {
'\x41' to '\x5a'

View File

@ -1,8 +1,4 @@
/*
Module: unsafe
Unsafe operations
*/
#[doc = "Unsafe operations"];
export reinterpret_cast, leak;
@ -12,11 +8,9 @@ native mod rusti {
fn leak<T>(-thing: T);
}
/*
Function: reinterpret_cast
#[doc = "
Casts the value at `src` to U. The two types must have the same length.
*/
"]
#[inline(always)]
unsafe fn reinterpret_cast<T, U>(src: T) -> U {
let t1 = sys::get_type_desc::<T>();
@ -27,16 +21,14 @@ unsafe fn reinterpret_cast<T, U>(src: T) -> U {
ret rusti::cast(src);
}
/*
Function: leak
Move `thing` into the void.
#[doc ="
Move a thing into the void
The leak function will take ownership of the provided value but neglect
to run any required cleanup or memory-management operations on it. This
can be used for various acts of magick, particularly when using
reinterpret_cast on managed pointer types.
*/
"]
#[inline(always)]
unsafe fn leak<T>(-thing: T) { rusti::leak(thing); }

File diff suppressed because it is too large Load Diff