libcore: Remove pure from libcore. rs=depure

This commit is contained in:
Patrick Walton
2013-03-21 21:20:48 -07:00
parent 4634f7edae
commit be9bddd463
57 changed files with 1548 additions and 1573 deletions
+11 -11
View File
@@ -38,7 +38,7 @@ pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
/// Returns the number of elements the vector can hold without reallocating
#[inline(always)]
pub pure fn capacity<T>(v: @[const T]) -> uint {
pub fn capacity<T>(v: @[const T]) -> uint {
unsafe {
let repr: **raw::VecRepr =
::cast::reinterpret_cast(&addr_of(&v));
@@ -59,8 +59,7 @@ pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build_sized<A>(size: uint,
builder: &fn(push: &pure fn(v: A))) -> @[A] {
pub fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> @[A] {
let mut vec: @[const A] = @[];
unsafe { raw::reserve(&mut vec, size); }
builder(|+x| unsafe { raw::push(&mut vec, x) });
@@ -78,7 +77,7 @@ pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> @[A] {
pub fn build<A>(builder: &fn(push: &fn(v: A))) -> @[A] {
build_sized(4, builder)
}
@@ -95,14 +94,15 @@ pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: &pure fn(v: A))) -> @[A] {
pub fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: &fn(v: A)))
-> @[A] {
build_sized(size.get_or_default(4), builder)
}
// Appending
#[inline(always)]
pub pure fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
pub fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
do build_sized(lhs.len() + rhs.len()) |push| {
for vec::each(lhs) |x| { push(*x); }
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
@@ -111,7 +111,7 @@ pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
/// Apply a function to each element of a vector and return the results
pub pure fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
do build_sized(v.len()) |push| {
for vec::each(v) |elem| {
push(f(elem));
@@ -125,7 +125,7 @@ pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
pub fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(op(i)); i += 1u; }
@@ -138,7 +138,7 @@ pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value `t`.
*/
pub pure fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] {
pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(copy t); i += 1u; }
@@ -176,7 +176,7 @@ pub mod traits {
impl<T:Copy> Add<&'self [const T],@[T]> for @[T] {
#[inline(always)]
pure fn add(&self, rhs: & &'self [const T]) -> @[T] {
fn add(&self, rhs: & &'self [const T]) -> @[T] {
append(*self, (*rhs))
}
}
+14 -14
View File
@@ -17,39 +17,39 @@
#[cfg(notest)] use cmp;
/// Negation / inverse
pub pure fn not(v: bool) -> bool { !v }
pub fn not(v: bool) -> bool { !v }
/// Conjunction
pub pure fn and(a: bool, b: bool) -> bool { a && b }
pub fn and(a: bool, b: bool) -> bool { a && b }
/// Disjunction
pub pure fn or(a: bool, b: bool) -> bool { a || b }
pub fn or(a: bool, b: bool) -> bool { a || b }
/**
* Exclusive or
*
* Identical to `or(and(a, not(b)), and(not(a), b))`
*/
pub pure fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
pub fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
/// Implication in the logic, i.e. from `a` follows `b`
pub pure fn implies(a: bool, b: bool) -> bool { !a || b }
pub fn implies(a: bool, b: bool) -> bool { !a || b }
/// true if truth values `a` and `b` are indistinguishable in the logic
pub pure fn eq(a: bool, b: bool) -> bool { a == b }
pub fn eq(a: bool, b: bool) -> bool { a == b }
/// true if truth values `a` and `b` are distinguishable in the logic
pub pure fn ne(a: bool, b: bool) -> bool { a != b }
pub fn ne(a: bool, b: bool) -> bool { a != b }
/// true if `v` represents truth in the logic
pub pure fn is_true(v: bool) -> bool { v }
pub fn is_true(v: bool) -> bool { v }
/// true if `v` represents falsehood in the logic
pub pure fn is_false(v: bool) -> bool { !v }
pub fn is_false(v: bool) -> bool { !v }
/// Parse logic value from `s`
impl FromStr for bool {
pure fn from_str(s: &str) -> Option<bool> {
fn from_str(s: &str) -> Option<bool> {
if s == "true" {
Some(true)
} else if s == "false" {
@@ -61,7 +61,7 @@ impl FromStr for bool {
}
/// Convert `v` into a string
pub pure fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
pub fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
/**
* Iterates over all truth values by passing them to `blk` in an unspecified
@@ -73,12 +73,12 @@ pub fn all_values(blk: &fn(v: bool)) {
}
/// converts truth value to an 8 bit byte
pub pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
pub fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
#[cfg(notest)]
impl cmp::Eq for bool {
pure fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
pure fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
}
#[test]
+4 -4
View File
@@ -21,14 +21,14 @@ pub struct Cell<T> {
}
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
pure fn eq(&self, other: &Cell<T>) -> bool {
fn eq(&self, other: &Cell<T>) -> bool {
unsafe {
let frozen_self: &Option<T> = transmute(&mut self.value);
let frozen_other: &Option<T> = transmute(&mut other.value);
frozen_self == frozen_other
}
}
pure fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
}
/// Creates a new full cell with the given value.
@@ -36,7 +36,7 @@ pub fn Cell<T>(value: T) -> Cell<T> {
Cell { value: Some(value) }
}
pub pure fn empty_cell<T>() -> Cell<T> {
pub fn empty_cell<T>() -> Cell<T> {
Cell { value: None }
}
@@ -61,7 +61,7 @@ fn put_back(&self, value: T) {
}
/// Returns true if the cell is empty and false if the cell is full.
pure fn is_empty(&self) -> bool {
fn is_empty(&self) -> bool {
self.value.is_none()
}
+14 -14
View File
@@ -61,7 +61,7 @@
* in terms of the Unicode General Category 'Ll'
*/
#[inline(always)]
pub pure fn is_lowercase(c: char) -> bool {
pub fn is_lowercase(c: char) -> bool {
return unicode::general_category::Ll(c);
}
@@ -70,7 +70,7 @@
* in terms of the Unicode General Category 'Lu'.
*/
#[inline(always)]
pub pure fn is_uppercase(c: char) -> bool {
pub fn is_uppercase(c: char) -> bool {
return unicode::general_category::Lu(c);
}
@@ -80,7 +80,7 @@
* additional 'Cc'-category control codes in the range [0x09, 0x0d]
*/
#[inline(always)]
pub pure fn is_whitespace(c: char) -> bool {
pub fn is_whitespace(c: char) -> bool {
return ('\x09' <= c && c <= '\x0d')
|| unicode::general_category::Zs(c)
|| unicode::general_category::Zl(c)
@@ -93,7 +93,7 @@
* and the Derived Core Property 'Alphabetic'.
*/
#[inline(always)]
pub pure fn is_alphanumeric(c: char) -> bool {
pub fn is_alphanumeric(c: char) -> bool {
return unicode::derived_property::Alphabetic(c) ||
unicode::general_category::Nd(c) ||
unicode::general_category::Nl(c) ||
@@ -102,13 +102,13 @@
/// Indicates whether the character is an ASCII character
#[inline(always)]
pub pure fn is_ascii(c: char) -> bool {
pub fn is_ascii(c: char) -> bool {
c - ('\x7F' & c) == '\x00'
}
/// Indicates whether the character is numeric (Nd, Nl, or No)
#[inline(always)]
pub pure fn is_digit(c: char) -> bool {
pub fn is_digit(c: char) -> bool {
return unicode::general_category::Nd(c) ||
unicode::general_category::Nl(c) ||
unicode::general_category::No(c);
@@ -127,7 +127,7 @@
* Note: This just wraps `to_digit()`.
*/
#[inline(always)]
pub pure fn is_digit_radix(c: char, radix: uint) -> bool {
pub fn is_digit_radix(c: char, radix: uint) -> bool {
match to_digit(c, radix) {
Some(_) => true,
None => false
@@ -148,7 +148,7 @@
* Fails if given a `radix` outside the range `[0..36]`.
*/
#[inline]
pub pure fn to_digit(c: char, radix: uint) -> Option<uint> {
pub fn to_digit(c: char, radix: uint) -> Option<uint> {
if radix > 36 {
fail!(fmt!("to_digit: radix %? is to high (maximum 36)", radix));
}
@@ -171,7 +171,7 @@
* Fails if given an `radix` > 36.
*/
#[inline]
pub pure fn from_digit(num: uint, radix: uint) -> Option<char> {
pub fn from_digit(num: uint, radix: uint) -> Option<char> {
if radix > 36 {
fail!(fmt!("from_digit: radix %? is to high (maximum 36)", num));
}
@@ -195,7 +195,7 @@
* - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN`
* - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN`
*/
pub pure fn escape_unicode(c: char) -> ~str {
pub fn escape_unicode(c: char) -> ~str {
let s = u32::to_str_radix(c as u32, 16u);
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
else if c <= '\uffff' { ('u', 4u) }
@@ -223,7 +223,7 @@
* - Any other chars in the range [0x20,0x7e] are not escaped.
* - Any other chars are given hex unicode escapes; see `escape_unicode`.
*/
pub pure fn escape_default(c: char) -> ~str {
pub fn escape_default(c: char) -> ~str {
match c {
'\t' => ~"\\t",
'\r' => ~"\\r",
@@ -244,7 +244,7 @@
* -1 if a < b, 0 if a == b, +1 if a > b
*/
#[inline(always)]
pub pure fn cmp(a: char, b: char) -> int {
pub fn cmp(a: char, b: char) -> int {
return if b > a { -1 }
else if b < a { 1 }
else { 0 }
@@ -252,8 +252,8 @@
#[cfg(notest)]
impl Eq for char {
pure fn eq(&self, other: &char) -> bool { (*self) == (*other) }
pure fn ne(&self, other: &char) -> bool { (*self) != (*other) }
fn eq(&self, other: &char) -> bool { (*self) == (*other) }
fn ne(&self, other: &char) -> bool { (*self) != (*other) }
}
#[test]
+27 -27
View File
@@ -33,8 +33,8 @@
*/
#[lang="eq"]
pub trait Eq {
pure fn eq(&self, other: &Self) -> bool;
pure fn ne(&self, other: &Self) -> bool;
fn eq(&self, other: &Self) -> bool;
fn ne(&self, other: &Self) -> bool;
}
#[deriving(Eq)]
@@ -42,11 +42,11 @@ pub enum Ordering { Less, Equal, Greater }
/// Trait for types that form a total order
pub trait TotalOrd {
pure fn cmp(&self, other: &Self) -> Ordering;
fn cmp(&self, other: &Self) -> Ordering;
}
#[inline(always)]
pure fn icmp<T: Ord>(a: &T, b: &T) -> Ordering {
fn icmp<T: Ord>(a: &T, b: &T) -> Ordering {
if *a < *b { Less }
else if *a > *b { Greater }
else { Equal }
@@ -54,52 +54,52 @@ pub trait TotalOrd {
impl TotalOrd for u8 {
#[inline(always)]
pure fn cmp(&self, other: &u8) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &u8) -> Ordering { icmp(self, other) }
}
impl TotalOrd for u16 {
#[inline(always)]
pure fn cmp(&self, other: &u16) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &u16) -> Ordering { icmp(self, other) }
}
impl TotalOrd for u32 {
#[inline(always)]
pure fn cmp(&self, other: &u32) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &u32) -> Ordering { icmp(self, other) }
}
impl TotalOrd for u64 {
#[inline(always)]
pure fn cmp(&self, other: &u64) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &u64) -> Ordering { icmp(self, other) }
}
impl TotalOrd for i8 {
#[inline(always)]
pure fn cmp(&self, other: &i8) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &i8) -> Ordering { icmp(self, other) }
}
impl TotalOrd for i16 {
#[inline(always)]
pure fn cmp(&self, other: &i16) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &i16) -> Ordering { icmp(self, other) }
}
impl TotalOrd for i32 {
#[inline(always)]
pure fn cmp(&self, other: &i32) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &i32) -> Ordering { icmp(self, other) }
}
impl TotalOrd for i64 {
#[inline(always)]
pure fn cmp(&self, other: &i64) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &i64) -> Ordering { icmp(self, other) }
}
impl TotalOrd for int {
#[inline(always)]
pure fn cmp(&self, other: &int) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &int) -> Ordering { icmp(self, other) }
}
impl TotalOrd for uint {
#[inline(always)]
pure fn cmp(&self, other: &uint) -> Ordering { icmp(self, other) }
fn cmp(&self, other: &uint) -> Ordering { icmp(self, other) }
}
/**
@@ -114,39 +114,39 @@ impl TotalOrd for uint {
*/
#[lang="ord"]
pub trait Ord {
pure fn lt(&self, other: &Self) -> bool;
pure fn le(&self, other: &Self) -> bool;
pure fn ge(&self, other: &Self) -> bool;
pure fn gt(&self, other: &Self) -> bool;
fn lt(&self, other: &Self) -> bool;
fn le(&self, other: &Self) -> bool;
fn ge(&self, other: &Self) -> bool;
fn gt(&self, other: &Self) -> bool;
}
#[inline(always)]
pub pure fn lt<T:Ord>(v1: &T, v2: &T) -> bool {
pub fn lt<T:Ord>(v1: &T, v2: &T) -> bool {
(*v1).lt(v2)
}
#[inline(always)]
pub pure fn le<T:Ord>(v1: &T, v2: &T) -> bool {
pub fn le<T:Ord>(v1: &T, v2: &T) -> bool {
(*v1).le(v2)
}
#[inline(always)]
pub pure fn eq<T:Eq>(v1: &T, v2: &T) -> bool {
pub fn eq<T:Eq>(v1: &T, v2: &T) -> bool {
(*v1).eq(v2)
}
#[inline(always)]
pub pure fn ne<T:Eq>(v1: &T, v2: &T) -> bool {
pub fn ne<T:Eq>(v1: &T, v2: &T) -> bool {
(*v1).ne(v2)
}
#[inline(always)]
pub pure fn ge<T:Ord>(v1: &T, v2: &T) -> bool {
pub fn ge<T:Ord>(v1: &T, v2: &T) -> bool {
(*v1).ge(v2)
}
#[inline(always)]
pub pure fn gt<T:Ord>(v1: &T, v2: &T) -> bool {
pub fn gt<T:Ord>(v1: &T, v2: &T) -> bool {
(*v1).gt(v2)
}
@@ -155,16 +155,16 @@ pub trait Ord {
/// container types; e.g. it is often desirable to be able to use `&str`
/// values to look up entries in a container with `~str` keys.
pub trait Equiv<T> {
pure fn equiv(&self, other: &T) -> bool;
fn equiv(&self, other: &T) -> bool;
}
#[inline(always)]
pub pure fn min<T:Ord>(v1: T, v2: T) -> T {
pub fn min<T:Ord>(v1: T, v2: T) -> T {
if v1 < v2 { v1 } else { v2 }
}
#[inline(always)]
pub pure fn max<T:Ord>(v1: T, v2: T) -> T {
pub fn max<T:Ord>(v1: T, v2: T) -> T {
if v1 > v2 { v1 } else { v2 }
}
+8 -8
View File
@@ -50,7 +50,7 @@ pub trait GenericPort<T> {
/// Ports that can `peek`
pub trait Peekable<T> {
/// Returns true if a message is available
pure fn peek(&self) -> bool;
fn peek(&self) -> bool;
}
/// Returns the index of an endpoint that is ready to receive.
@@ -148,7 +148,7 @@ fn chan_try_send<T:Owned>(self: &Chan<T>, x: T) -> bool {
pub impl<T: Owned> Port<T> {
fn recv(&self) -> T { port_recv(self) }
fn try_recv(&self) -> Option<T> { port_try_recv(self) }
pure fn peek(&self) -> bool { port_peek(self) }
fn peek(&self) -> bool { port_peek(self) }
}
impl<T: Owned> GenericPort<T> for Port<T> {
@@ -180,11 +180,11 @@ fn port_try_recv<T:Owned>(self: &Port<T>) -> Option<T> {
}
impl<T: Owned> Peekable<T> for Port<T> {
pure fn peek(&self) -> bool { port_peek(self) }
fn peek(&self) -> bool { port_peek(self) }
}
#[inline(always)]
pure fn port_peek<T:Owned>(self: &Port<T>) -> bool {
fn port_peek<T:Owned>(self: &Port<T>) -> bool {
unsafe {
let mut endp = None;
endp <-> self.endp;
@@ -198,7 +198,7 @@ impl<T: Owned> Peekable<T> for Port<T> {
}
impl<T: Owned> Selectable for Port<T> {
pure fn header(&self) -> *PacketHeader {
fn header(&self) -> *PacketHeader {
unsafe {
match self.endp {
Some(ref endp) => endp.header(),
@@ -223,7 +223,7 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{
pub impl<T:Owned> PortSet<T> {
fn recv(&self) -> T { port_set_recv(self) }
fn try_recv(&self) -> Option<T> { port_set_try_recv(self) }
pure fn peek(&self) -> bool { port_set_peek(self) }
fn peek(&self) -> bool { port_set_peek(self) }
}
pub impl<T: Owned> PortSet<T> {
@@ -272,11 +272,11 @@ fn port_set_try_recv<T:Owned>(self: &PortSet<T>) -> Option<T> {
}
impl<T: Owned> Peekable<T> for PortSet<T> {
pure fn peek(&self) -> bool { port_set_peek(self) }
fn peek(&self) -> bool { port_set_peek(self) }
}
#[inline(always)]
pure fn port_set_peek<T:Owned>(self: &PortSet<T>) -> bool {
fn port_set_peek<T:Owned>(self: &PortSet<T>) -> bool {
// It'd be nice to use self.port.each, but that version isn't
// pure.
for uint::range(0, vec::uniq_len(&const self.ports)) |i| {
+14 -14
View File
@@ -14,10 +14,10 @@
pub trait Container {
/// Return the number of elements in the container
pure fn len(&const self) -> uint;
fn len(&const self) -> uint;
/// Return true if the container contains no elements
pure fn is_empty(&const self) -> bool;
fn is_empty(&const self) -> bool;
}
pub trait Mutable: Container {
@@ -27,19 +27,19 @@ pub trait Mutable: Container {
pub trait Map<K, V>: Mutable {
/// Return true if the map contains a value for the specified key
pure fn contains_key(&self, key: &K) -> bool;
fn contains_key(&self, key: &K) -> bool;
/// Visit all keys
pure fn each_key(&self, f: &fn(&K) -> bool);
fn each_key(&self, f: &fn(&K) -> bool);
/// Visit all values
pure fn each_value(&self, f: &fn(&V) -> bool);
fn each_value(&self, f: &fn(&V) -> bool);
/// Iterate over the map and mutate the contained values
fn mutate_values(&mut self, f: &fn(&K, &mut V) -> bool);
/// Return the value corresponding to the key in the map
pure fn find(&self, key: &K) -> Option<&'self V>;
fn find(&self, key: &K) -> Option<&'self V>;
/// Insert a key-value pair into the map. An existing value for a
/// key is replaced by the new value. Return true if the key did
@@ -53,7 +53,7 @@ pub trait Map<K, V>: Mutable {
pub trait Set<T>: Mutable {
/// Return true if the set contains a value
pure fn contains(&self, value: &T) -> bool;
fn contains(&self, value: &T) -> bool;
/// Add a value to the set. Return true if the value was not already
/// present in the set.
@@ -65,23 +65,23 @@ pub trait Set<T>: Mutable {
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
pure fn is_disjoint(&self, other: &Self) -> bool;
fn is_disjoint(&self, other: &Self) -> bool;
/// Return true if the set is a subset of another
pure fn is_subset(&self, other: &Self) -> bool;
fn is_subset(&self, other: &Self) -> bool;
/// Return true if the set is a superset of another
pure fn is_superset(&self, other: &Self) -> bool;
fn is_superset(&self, other: &Self) -> bool;
/// Visit the values representing the difference
pure fn difference(&self, other: &Self, f: &fn(&T) -> bool);
fn difference(&self, other: &Self, f: &fn(&T) -> bool);
/// Visit the values representing the symmetric difference
pure fn symmetric_difference(&self, other: &Self, f: &fn(&T) -> bool);
fn symmetric_difference(&self, other: &Self, f: &fn(&T) -> bool);
/// Visit the values representing the intersection
pure fn intersection(&self, other: &Self, f: &fn(&T) -> bool);
fn intersection(&self, other: &Self, f: &fn(&T) -> bool);
/// Visit the values representing the union
pure fn union(&self, other: &Self, f: &fn(&T) -> bool);
fn union(&self, other: &Self, f: &fn(&T) -> bool);
}
+24 -24
View File
@@ -42,7 +42,7 @@ pub struct DList<T> {
}
priv impl<T> DListNode<T> {
pure fn assert_links(@mut self) {
fn assert_links(@mut self) {
match self.next {
Some(neighbour) => match neighbour.prev {
Some(me) => if !managed::mut_ptr_eq(self, me) {
@@ -66,24 +66,24 @@ pub struct DList<T> {
pub impl<T> DListNode<T> {
/// Get the next node in the list, if there is one.
pure fn next_link(@mut self) -> DListLink<T> {
fn next_link(@mut self) -> DListLink<T> {
self.assert_links();
self.next
}
/// Get the next node in the list, failing if there isn't one.
pure fn next_node(@mut self) -> @mut DListNode<T> {
fn next_node(@mut self) -> @mut DListNode<T> {
match self.next_link() {
Some(nobe) => nobe,
None => fail!(~"This dlist node has no next neighbour.")
}
}
/// Get the previous node in the list, if there is one.
pure fn prev_link(@mut self) -> DListLink<T> {
fn prev_link(@mut self) -> DListLink<T> {
self.assert_links();
self.prev
}
/// Get the previous node in the list, failing if there isn't one.
pure fn prev_node(@mut self) -> @mut DListNode<T> {
fn prev_node(@mut self) -> @mut DListNode<T> {
match self.prev_link() {
Some(nobe) => nobe,
None => fail!(~"This dlist node has no previous neighbour.")
@@ -92,17 +92,17 @@ pub impl<T> DListNode<T> {
}
/// Creates a new dlist node with the given data.
pub pure fn new_dlist_node<T>(data: T) -> @mut DListNode<T> {
pub fn new_dlist_node<T>(data: T) -> @mut DListNode<T> {
@mut DListNode { data: data, linked: false, prev: None, next: None }
}
/// Creates a new, empty dlist.
pub pure fn DList<T>() -> @mut DList<T> {
pub fn DList<T>() -> @mut DList<T> {
@mut DList { size: 0, hd: None, tl: None }
}
/// Creates a new dlist with a single element
pub pure fn from_elem<T>(data: T) -> @mut DList<T> {
pub fn from_elem<T>(data: T) -> @mut DList<T> {
let list = DList();
unsafe { list.push(data); }
list
@@ -126,7 +126,7 @@ pub fn concat<T>(lists: @mut DList<@mut DList<T>>) -> @mut DList<T> {
}
priv impl<T> DList<T> {
pure fn new_link(data: T) -> DListLink<T> {
fn new_link(data: T) -> DListLink<T> {
Some(@mut DListNode {
data: data,
linked: true,
@@ -134,7 +134,7 @@ pub fn concat<T>(lists: @mut DList<@mut DList<T>>) -> @mut DList<T> {
next: None
})
}
pure fn assert_mine(@mut self, nobe: @mut DListNode<T>) {
fn assert_mine(@mut self, nobe: @mut DListNode<T>) {
// These asserts could be stronger if we had node-root back-pointers,
// but those wouldn't allow for O(1) append.
if self.size == 0 {
@@ -212,9 +212,9 @@ fn insert_right(@mut self,
pub impl<T> DList<T> {
/// Get the size of the list. O(1).
pure fn len(@mut self) -> uint { self.size }
fn len(@mut self) -> uint { self.size }
/// Returns true if the list is empty. O(1).
pure fn is_empty(@mut self) -> bool { self.len() == 0 }
fn is_empty(@mut self) -> bool { self.len() == 0 }
/// Add data to the head of the list. O(1).
fn push_head(@mut self, data: T) {
@@ -316,12 +316,12 @@ fn pop_tail_n(@mut self) -> DListLink<T> {
tl
}
/// Get the node at the list's head. O(1).
pure fn peek_n(@mut self) -> DListLink<T> { self.hd }
fn peek_n(@mut self) -> DListLink<T> { self.hd }
/// Get the node at the list's tail. O(1).
pure fn peek_tail_n(@mut self) -> DListLink<T> { self.tl }
fn peek_tail_n(@mut self) -> DListLink<T> { self.tl }
/// Get the node at the list's head, failing if empty. O(1).
pure fn head_n(@mut self) -> @mut DListNode<T> {
fn head_n(@mut self) -> @mut DListNode<T> {
match self.hd {
Some(nobe) => nobe,
None => fail!(
@@ -329,7 +329,7 @@ fn pop_tail_n(@mut self) -> DListLink<T> {
}
}
/// Get the node at the list's tail, failing if empty. O(1).
pure fn tail_n(@mut self) -> @mut DListNode<T> {
fn tail_n(@mut self) -> @mut DListNode<T> {
match self.tl {
Some(nobe) => nobe,
None => fail!(
@@ -399,7 +399,7 @@ fn clear(@mut self) {
}
/// Iterate over nodes.
pure fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) {
fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) {
let mut link = self.peek_n();
while link.is_some() {
let nobe = link.get();
@@ -471,23 +471,23 @@ fn pop_tail(@mut self) -> Option<T> {
}
/// Get data at the list's head. O(1).
pure fn peek(@mut self) -> Option<T> {
fn peek(@mut self) -> Option<T> {
self.peek_n().map(|nobe| nobe.data)
}
/// Get data at the list's tail. O(1).
pure fn peek_tail(@mut self) -> Option<T> {
fn peek_tail(@mut self) -> Option<T> {
self.peek_tail_n().map (|nobe| nobe.data)
}
/// Get data at the list's head, failing if empty. O(1).
pure fn head(@mut self) -> T { self.head_n().data }
fn head(@mut self) -> T { self.head_n().data }
/// Get data at the list's tail, failing if empty. O(1).
pure fn tail(@mut self) -> T { self.tail_n().data }
fn tail(@mut self) -> T { self.tail_n().data }
/// Get the elements of the list as a vector. O(n).
pure fn to_vec(@mut self) -> ~[T] {
fn to_vec(@mut self) -> ~[T] {
let mut v = vec::with_capacity(self.size);
unsafe {
// Take this out of the unchecked when iter's functions are pure
@@ -507,7 +507,7 @@ impl<T> BaseIter<T> for @mut DList<T> {
* allow for e.g. breadth-first search with in-place enqueues), but
* removing the current node is forbidden.
*/
pure fn each(&self, f: &fn(v: &T) -> bool) {
fn each(&self, f: &fn(v: &T) -> bool) {
let mut link = self.peek_n();
while option::is_some(&link) {
let nobe = option::get(link);
@@ -536,7 +536,7 @@ impl<T> BaseIter<T> for @mut DList<T> {
}
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
#[cfg(test)]
+6 -6
View File
@@ -87,7 +87,7 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>])
}
#[inline(always)]
pub pure fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
//! Flips between left and right of a given either
match eith {
@@ -97,7 +97,7 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>])
}
#[inline(always)]
pub pure fn to_result<T, U>(eith: Either<T, U>)
pub fn to_result<T, U>(eith: Either<T, U>)
-> Result<U, T> {
/*!
* Converts either::t to a result::t
@@ -113,21 +113,21 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>])
}
#[inline(always)]
pub pure fn is_left<T, U>(eith: &Either<T, U>) -> bool {
pub fn is_left<T, U>(eith: &Either<T, U>) -> bool {
//! Checks whether the given value is a left
match *eith { Left(_) => true, _ => false }
}
#[inline(always)]
pub pure fn is_right<T, U>(eith: &Either<T, U>) -> bool {
pub fn is_right<T, U>(eith: &Either<T, U>) -> bool {
//! Checks whether the given value is a right
match *eith { Right(_) => true, _ => false }
}
#[inline(always)]
pub pure fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
pub fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
//! Retrieves the value in the left branch. Fails if the either is Right.
match eith {
@@ -137,7 +137,7 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>])
}
#[inline(always)]
pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
pub fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
//! Retrieves the value in the right branch. Fails if the either is Left.
match eith {
+1 -1
View File
@@ -13,5 +13,5 @@
use option::Option;
pub trait FromStr {
pure fn from_str(s: &str) -> Option<Self>;
fn from_str(s: &str) -> Option<Self>;
}
+20 -22
View File
@@ -50,17 +50,17 @@ pub trait Hash {
* function and require most types to only implement the
* IterBytes trait, that feeds SipHash.
*/
pure fn hash_keyed(&self, k0: u64, k1: u64) -> u64;
fn hash_keyed(&self, k0: u64, k1: u64) -> u64;
}
// When we have default methods, won't need this.
pub trait HashUtil {
pure fn hash(&self) -> u64;
fn hash(&self) -> u64;
}
impl<A:Hash> HashUtil for A {
#[inline(always)]
pure fn hash(&self) -> u64 { self.hash_keyed(0,0) }
fn hash(&self) -> u64 { self.hash_keyed(0,0) }
}
/// Streaming hash-functions should implement this.
@@ -75,7 +75,7 @@ pub trait Streaming {
impl<A:IterBytes> Hash for A {
#[inline(always)]
pure fn hash_keyed(&self, k0: u64, k1: u64) -> u64 {
fn hash_keyed(&self, k0: u64, k1: u64) -> u64 {
unsafe {
let s = &State(k0, k1);
for self.iter_bytes(true) |bytes| {
@@ -86,9 +86,8 @@ impl<A:IterBytes> Hash for A {
}
}
pure fn hash_keyed_2<A: IterBytes,
B: IterBytes>(a: &A, b: &B,
k0: u64, k1: u64) -> u64 {
fn hash_keyed_2<A: IterBytes,
B: IterBytes>(a: &A, b: &B, k0: u64, k1: u64) -> u64 {
unsafe {
let s = &State(k0, k1);
for a.iter_bytes(true) |bytes| { s.input(bytes); }
@@ -97,10 +96,9 @@ impl<A:IterBytes> Hash for A {
}
}
pure fn hash_keyed_3<A: IterBytes,
B: IterBytes,
C: IterBytes>(a: &A, b: &B, c: &C,
k0: u64, k1: u64) -> u64 {
fn hash_keyed_3<A: IterBytes,
B: IterBytes,
C: IterBytes>(a: &A, b: &B, c: &C, k0: u64, k1: u64) -> u64 {
unsafe {
let s = &State(k0, k1);
for a.iter_bytes(true) |bytes| { s.input(bytes); }
@@ -110,11 +108,11 @@ impl<A:IterBytes> Hash for A {
}
}
pure fn hash_keyed_4<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes>(a: &A, b: &B, c: &C, d: &D,
k0: u64, k1: u64) -> u64 {
fn hash_keyed_4<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes>(a: &A, b: &B, c: &C, d: &D, k0: u64, k1: u64)
-> u64 {
unsafe {
let s = &State(k0, k1);
for a.iter_bytes(true) |bytes| { s.input(bytes); }
@@ -125,12 +123,12 @@ impl<A:IterBytes> Hash for A {
}
}
pure fn hash_keyed_5<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes,
E: IterBytes>(a: &A, b: &B, c: &C, d: &D, e: &E,
k0: u64, k1: u64) -> u64 {
fn hash_keyed_5<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes,
E: IterBytes>(a: &A, b: &B, c: &C, d: &D, e: &E,
k0: u64, k1: u64) -> u64 {
unsafe {
let s = &State(k0, k1);
for a.iter_bytes(true) |bytes| { s.input(bytes); }
+49 -58
View File
@@ -48,7 +48,7 @@ enum SearchResult {
}
#[inline(always)]
pure fn resize_at(capacity: uint) -> uint {
fn resize_at(capacity: uint) -> uint {
((capacity as float) * 3. / 4.) as uint
}
@@ -59,7 +59,7 @@ pub fn linear_map_with_capacity<K:Eq + Hash,V>(
initial_capacity)
}
pure fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
k0: u64, k1: u64,
initial_capacity: uint) -> LinearMap<K, V> {
LinearMap {
@@ -72,21 +72,21 @@ pub fn linear_map_with_capacity<K:Eq + Hash,V>(
priv impl<K:Hash + IterBytes + Eq,V> LinearMap<K, V> {
#[inline(always)]
pure fn to_bucket(&self, h: uint) -> uint {
fn to_bucket(&self, h: uint) -> uint {
// A good hash function with entropy spread over all of the
// bits is assumed. SipHash is more than good enough.
h % self.buckets.len()
}
#[inline(always)]
pure fn next_bucket(&self, idx: uint, len_buckets: uint) -> uint {
fn next_bucket(&self, idx: uint, len_buckets: uint) -> uint {
let n = (idx + 1) % len_buckets;
debug!("next_bucket(%?, %?) = %?", idx, len_buckets, n);
n
}
#[inline(always)]
pure fn bucket_sequence(&self, hash: uint,
fn bucket_sequence(&self, hash: uint,
op: &fn(uint) -> bool) -> uint {
let start_idx = self.to_bucket(hash);
let len_buckets = self.buckets.len();
@@ -103,24 +103,24 @@ pub fn linear_map_with_capacity<K:Eq + Hash,V>(
}
#[inline(always)]
pure fn bucket_for_key(&self, k: &K) -> SearchResult {
fn bucket_for_key(&self, k: &K) -> SearchResult {
let hash = k.hash_keyed(self.k0, self.k1) as uint;
self.bucket_for_key_with_hash(hash, k)
}
#[inline(always)]
pure fn bucket_for_key_equiv<Q:Hash + IterBytes + Equiv<K>>(
&self,
k: &Q)
-> SearchResult {
fn bucket_for_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self,
k: &Q)
-> SearchResult {
let hash = k.hash_keyed(self.k0, self.k1) as uint;
self.bucket_for_key_with_hash_equiv(hash, k)
}
#[inline(always)]
pure fn bucket_for_key_with_hash(&self,
hash: uint,
k: &K) -> SearchResult {
fn bucket_for_key_with_hash(&self,
hash: uint,
k: &K)
-> SearchResult {
let _ = for self.bucket_sequence(hash) |i| {
match self.buckets[i] {
Some(ref bkt) => if bkt.hash == hash && *k == bkt.key {
@@ -133,10 +133,10 @@ pub fn linear_map_with_capacity<K:Eq + Hash,V>(
}
#[inline(always)]
pure fn bucket_for_key_with_hash_equiv<Q:Equiv<K>>(&self,
hash: uint,
k: &Q)
-> SearchResult {
fn bucket_for_key_with_hash_equiv<Q:Equiv<K>>(&self,
hash: uint,
k: &Q)
-> SearchResult {
let _ = for self.bucket_sequence(hash) |i| {
match self.buckets[i] {
Some(ref bkt) => {
@@ -185,7 +185,7 @@ fn insert_opt_bucket(&mut self, bucket: Option<Bucket<K, V>>) {
}
#[inline(always)]
pure fn value_for_bucket(&self, idx: uint) -> &'self V {
fn value_for_bucket(&self, idx: uint) -> &'self V {
match self.buckets[idx] {
Some(ref bkt) => &bkt.value,
None => fail!(~"LinearMap::find: internal logic error"),
@@ -273,7 +273,7 @@ impl<K:Hash + IterBytes + Eq,V>
BaseIter<(&'self K, &'self V)> for LinearMap<K, V>
{
/// Visit all key-value pairs
pure fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
fn each(&self, blk: &fn(&(&'self K, &'self V)) -> bool) {
for uint::range(0, self.buckets.len()) |i| {
let mut broke = false;
do self.buckets[i].map |bucket| {
@@ -284,16 +284,16 @@ impl<K:Hash + IterBytes + Eq,V>
if broke { break; }
}
}
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<K:Hash + IterBytes + Eq,V> Container for LinearMap<K, V> {
/// Return the number of elements in the map
pure fn len(&const self) -> uint { self.size }
fn len(&const self) -> uint { self.size }
/// Return true if the map contains no elements
pure fn is_empty(&const self) -> bool { self.len() == 0 }
fn is_empty(&const self) -> bool { self.len() == 0 }
}
impl<K:Hash + IterBytes + Eq,V> Mutable for LinearMap<K, V> {
@@ -308,7 +308,7 @@ fn clear(&mut self) {
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
/// Return true if the map contains a value for the specified key
pure fn contains_key(&self, k: &K) -> bool {
fn contains_key(&self, k: &K) -> bool {
match self.bucket_for_key(k) {
FoundEntry(_) => {true}
TableFull | FoundHole(_) => {false}
@@ -316,12 +316,12 @@ impl<K:Hash + IterBytes + Eq,V> Map<K, V> for LinearMap<K, V> {
}
/// Visit all keys
pure fn each_key(&self, blk: &fn(k: &K) -> bool) {
fn each_key(&self, blk: &fn(k: &K) -> bool) {
self.each(|&(k, _)| blk(k))
}
/// Visit all values
pure fn each_value(&self, blk: &fn(v: &V) -> bool) {
fn each_value(&self, blk: &fn(v: &V) -> bool) {
self.each(|&(_, v)| blk(v))
}
@@ -339,7 +339,7 @@ fn mutate_values(&mut self, blk: &fn(&'self K,
}
/// Return the value corresponding to the key in the map
pure fn find(&self, k: &K) -> Option<&'self V> {
fn find(&self, k: &K) -> Option<&'self V> {
match self.bucket_for_key(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
TableFull | FoundHole(_) => None,
@@ -487,7 +487,7 @@ fn consume(&mut self, f: &fn(K, V)) {
}
}
pure fn get(&self, k: &K) -> &'self V {
fn get(&self, k: &K) -> &'self V {
match self.find(k) {
Some(v) => v,
None => fail!(fmt!("No entry found for key: %?", k)),
@@ -496,10 +496,8 @@ fn consume(&mut self, f: &fn(K, V)) {
/// Return true if the map contains a value for the specified key,
/// using equivalence
pure fn contains_key_equiv<Q:Hash + IterBytes + Equiv<K>>(
&self,
key: &Q)
-> bool {
fn contains_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, key: &Q)
-> bool {
match self.bucket_for_key_equiv(key) {
FoundEntry(_) => {true}
TableFull | FoundHole(_) => {false}
@@ -508,8 +506,8 @@ fn consume(&mut self, f: &fn(K, V)) {
/// Return the value corresponding to the key in the map, using
/// equivalence
pure fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q)
-> Option<&'self V> {
fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q)
-> Option<&'self V> {
match self.bucket_for_key_equiv(k) {
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
TableFull | FoundHole(_) => None,
@@ -518,7 +516,7 @@ fn consume(&mut self, f: &fn(K, V)) {
}
impl<K:Hash + IterBytes + Eq,V:Eq> Eq for LinearMap<K, V> {
pure fn eq(&self, other: &LinearMap<K, V>) -> bool {
fn eq(&self, other: &LinearMap<K, V>) -> bool {
if self.len() != other.len() { return false; }
for self.each |&(key, value)| {
@@ -531,7 +529,7 @@ impl<K:Hash + IterBytes + Eq,V:Eq> Eq for LinearMap<K, V> {
true
}
pure fn ne(&self, other: &LinearMap<K, V>) -> bool { !self.eq(other) }
fn ne(&self, other: &LinearMap<K, V>) -> bool { !self.eq(other) }
}
pub struct LinearSet<T> {
@@ -540,25 +538,21 @@ pub struct LinearSet<T> {
impl<T:Hash + IterBytes + Eq> BaseIter<T> for LinearSet<T> {
/// Visit all values in order
pure fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<T:Hash + IterBytes + Eq> Eq for LinearSet<T> {
pure fn eq(&self, other: &LinearSet<T>) -> bool {
self.map == other.map
}
pure fn ne(&self, other: &LinearSet<T>) -> bool {
self.map != other.map
}
fn eq(&self, other: &LinearSet<T>) -> bool { self.map == other.map }
fn ne(&self, other: &LinearSet<T>) -> bool { self.map != other.map }
}
impl<T:Hash + IterBytes + Eq> Container for LinearSet<T> {
/// Return the number of elements in the set
pure fn len(&const self) -> uint { self.map.len() }
fn len(&const self) -> uint { self.map.len() }
/// Return true if the set contains no elements
pure fn is_empty(&const self) -> bool { self.map.is_empty() }
fn is_empty(&const self) -> bool { self.map.is_empty() }
}
impl<T:Hash + IterBytes + Eq> Mutable for LinearSet<T> {
@@ -568,9 +562,7 @@ fn clear(&mut self) { self.map.clear() }
impl<T:Hash + IterBytes + Eq> Set<T> for LinearSet<T> {
/// Return true if the set contains a value
pure fn contains(&self, value: &T) -> bool {
self.map.contains_key(value)
}
fn contains(&self, value: &T) -> bool { self.map.contains_key(value) }
/// Add a value to the set. Return true if the value was not already
/// present in the set.
@@ -582,22 +574,22 @@ fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
pure fn is_disjoint(&self, other: &LinearSet<T>) -> bool {
fn is_disjoint(&self, other: &LinearSet<T>) -> bool {
iter::all(self, |v| !other.contains(v))
}
/// Return true if the set is a subset of another
pure fn is_subset(&self, other: &LinearSet<T>) -> bool {
fn is_subset(&self, other: &LinearSet<T>) -> bool {
iter::all(self, |v| other.contains(v))
}
/// Return true if the set is a superset of another
pure fn is_superset(&self, other: &LinearSet<T>) -> bool {
fn is_superset(&self, other: &LinearSet<T>) -> bool {
other.is_subset(self)
}
/// Visit the values representing the difference
pure fn difference(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
fn difference(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
for self.each |v| {
if !other.contains(v) {
if !f(v) { return }
@@ -606,16 +598,15 @@ fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
}
/// Visit the values representing the symmetric difference
pure fn symmetric_difference(&self, other: &LinearSet<T>,
f: &fn(&T) -> bool) {
fn symmetric_difference(&self,
other: &LinearSet<T>,
f: &fn(&T) -> bool) {
self.difference(other, f);
other.difference(self, f);
}
/// Visit the values representing the intersection
pure fn intersection(&self,
other: &LinearSet<T>,
f: &fn(&T) -> bool) {
fn intersection(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
for self.each |v| {
if other.contains(v) {
if !f(v) { return }
@@ -624,7 +615,7 @@ fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
}
/// Visit the values representing the union
pure fn union(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
fn union(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
for self.each |v| {
if !f(v) { return }
}
+5 -5
View File
@@ -646,11 +646,11 @@ fn seek(&self, offset: int, whence: SeekStyle) {
fn tell(&self) -> uint { self.pos }
}
pub pure fn with_bytes_reader<t>(bytes: &[u8], f: &fn(@Reader) -> t) -> t {
pub fn with_bytes_reader<t>(bytes: &[u8], f: &fn(@Reader) -> t) -> t {
f(@BytesReader { bytes: bytes, pos: 0u } as @Reader)
}
pub pure fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
pub fn with_str_reader<T>(s: &str, f: &fn(@Reader) -> T) -> T {
str::byte_slice(s, |bytes| with_bytes_reader(bytes, f))
}
@@ -1165,18 +1165,18 @@ fn flush(&self) -> int { 0 }
fn get_type(&self) -> WriterType { File }
}
pub pure fn BytesWriter() -> BytesWriter {
pub fn BytesWriter() -> BytesWriter {
BytesWriter { bytes: ~[], mut pos: 0u }
}
pub pure fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
pub fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] {
let wr = @BytesWriter();
f(wr as @Writer);
let @BytesWriter{bytes, _} = wr;
return bytes;
}
pub pure fn with_str_writer(f: &fn(@Writer)) -> ~str {
pub fn with_str_writer(f: &fn(@Writer)) -> ~str {
let mut v = with_bytes_writer(f);
// FIXME (#3758): This should not be needed.
+50 -63
View File
@@ -23,12 +23,12 @@
pub type InitOp<T> = &'self fn(uint) -> T;
pub trait BaseIter<A> {
pure fn each(&self, blk: &fn(v: &A) -> bool);
pure fn size_hint(&self) -> Option<uint>;
fn each(&self, blk: &fn(v: &A) -> bool);
fn size_hint(&self) -> Option<uint>;
}
pub trait ReverseIter<A>: BaseIter<A> {
pure fn each_reverse(&self, blk: &fn(&A) -> bool);
fn each_reverse(&self, blk: &fn(&A) -> bool);
}
pub trait MutableIter<A>: BaseIter<A> {
@@ -36,41 +36,40 @@ pub trait MutableIter<A>: BaseIter<A> {
}
pub trait ExtendedIter<A> {
pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool);
pure fn all(&self, blk: &fn(&A) -> bool) -> bool;
pure fn any(&self, blk: &fn(&A) -> bool) -> bool;
pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B;
pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint>;
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B];
pure fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B];
fn eachi(&self, blk: &fn(uint, v: &A) -> bool);
fn all(&self, blk: &fn(&A) -> bool) -> bool;
fn any(&self, blk: &fn(&A) -> bool) -> bool;
fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B;
fn position(&self, f: &fn(&A) -> bool) -> Option<uint>;
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B];
fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B];
}
pub trait EqIter<A:Eq> {
pure fn contains(&self, x: &A) -> bool;
pure fn count(&self, x: &A) -> uint;
fn contains(&self, x: &A) -> bool;
fn count(&self, x: &A) -> uint;
}
pub trait Times {
pure fn times(&self, it: &fn() -> bool);
fn times(&self, it: &fn() -> bool);
}
pub trait CopyableIter<A:Copy> {
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A];
pure fn to_vec(&self) -> ~[A];
pure fn find(&self, p: &fn(&A) -> bool) -> Option<A>;
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A];
fn to_vec(&self) -> ~[A];
fn find(&self, p: &fn(&A) -> bool) -> Option<A>;
}
pub trait CopyableOrderedIter<A:Copy + Ord> {
pure fn min(&self) -> A;
pure fn max(&self) -> A;
fn min(&self) -> A;
fn max(&self) -> A;
}
pub trait CopyableNonstrictIter<A:Copy> {
// Like "each", but copies out the value. If the receiver is mutated while
// iterating over it, the semantics must not be memory-unsafe but are
// otherwise undefined.
pure fn each_val(&const self, f: &fn(A) -> bool);
fn each_val(&const self, f: &fn(A) -> bool);
}
// A trait for sequences that can be built by imperatively pushing elements
@@ -89,13 +88,11 @@ pub trait Buildable<A> {
* as an argument a function that will push an element
* onto the sequence being constructed.
*/
pure fn build_sized(size: uint,
builder: &fn(push: &pure fn(A))) -> Self;
fn build_sized(size: uint, builder: &fn(push: &fn(A))) -> Self;
}
#[inline(always)]
pub pure fn eachi<A,IA:BaseIter<A>>(self: &IA,
blk: &fn(uint, &A) -> bool) {
pub fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) {
let mut i = 0;
for self.each |a| {
if !blk(i, a) { break; }
@@ -104,8 +101,7 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn all<A,IA:BaseIter<A>>(self: &IA,
blk: &fn(&A) -> bool) -> bool {
pub fn all<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
for self.each |a| {
if !blk(a) { return false; }
}
@@ -113,8 +109,7 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn any<A,IA:BaseIter<A>>(self: &IA,
blk: &fn(&A) -> bool) -> bool {
pub fn any<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
for self.each |a| {
if blk(a) { return true; }
}
@@ -122,8 +117,9 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(
self: &IA, prd: &fn(&A) -> bool) -> ~[A] {
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: &IA,
prd: &fn(&A) -> bool)
-> ~[A] {
do vec::build_sized_opt(self.size_hint()) |push| {
for self.each |a| {
if prd(a) { push(*a); }
@@ -132,9 +128,7 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA,
op: &fn(&A) -> B)
-> ~[B] {
pub fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA, op: &fn(&A) -> B) -> ~[B] {
do vec::build_sized_opt(self.size_hint()) |push| {
for self.each |a| {
push(op(a));
@@ -143,8 +137,9 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(
self: &IA, op: &fn(&A) -> IB) -> ~[B] {
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(self: &IA,
op: &fn(&A) -> IB)
-> ~[B] {
do vec::build |push| {
for self.each |a| {
for op(a).each |&b| {
@@ -155,9 +150,8 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B,
blk: &fn(&B, &A) -> B)
-> B {
pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
-> B {
let mut b = b0;
for self.each |a| {
b = blk(&b, a);
@@ -166,12 +160,12 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
}
#[inline(always)]
pub pure fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
pub fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
for self.each |a| {
if *a == *x { return true; }
}
@@ -179,7 +173,7 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
pub fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
do foldl(self, 0) |count, value| {
if *value == *x {
*count + 1
@@ -190,9 +184,8 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
-> Option<uint>
{
pub fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
-> Option<uint> {
let mut i = 0;
for self.each |a| {
if f(a) { return Some(i); }
@@ -206,7 +199,7 @@ pub trait Buildable<A> {
// it would have to be implemented with foldr, which is too inefficient.
#[inline(always)]
pub pure fn repeat(times: uint, blk: &fn() -> bool) {
pub fn repeat(times: uint, blk: &fn() -> bool) {
let mut i = 0;
while i < times {
if !blk() { break }
@@ -215,7 +208,7 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
match a {
&Some(ref a_) if *a_ < *b => {
@@ -230,7 +223,7 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
match a {
&Some(ref a_) if *a_ > *b => {
@@ -245,8 +238,8 @@ pub trait Buildable<A> {
}
#[inline(always)]
pub pure fn find<A:Copy,IA:BaseIter<A>>(self: &IA,
f: &fn(&A) -> bool) -> Option<A> {
pub fn find<A:Copy,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
-> Option<A> {
for self.each |i| {
if f(i) { return Some(*i) }
}
@@ -266,8 +259,7 @@ pub trait Buildable<A> {
* onto the sequence being constructed.
*/
#[inline(always)]
pub pure fn build<A,B: Buildable<A>>(builder: &fn(push: &pure fn(A)))
-> B {
pub fn build<A,B: Buildable<A>>(builder: &fn(push: &fn(A))) -> B {
Buildable::build_sized(4, builder)
}
@@ -285,10 +277,8 @@ pub trait Buildable<A> {
* onto the sequence being constructed.
*/
#[inline(always)]
pub pure fn build_sized_opt<A,B: Buildable<A>>(
size: Option<uint>,
builder: &fn(push: &pure fn(A))) -> B {
pub fn build_sized_opt<A,B: Buildable<A>>(size: Option<uint>,
builder: &fn(push: &fn(A))) -> B {
Buildable::build_sized(size.get_or_default(4), builder)
}
@@ -312,8 +302,7 @@ pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
* to the value returned by the function `op`.
*/
#[inline(always)]
pub pure fn from_fn<T,BT: Buildable<T>>(n_elts: uint,
op: InitOp<T>) -> BT {
pub fn from_fn<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
do Buildable::build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(op(i)); i += 1u; }
@@ -327,8 +316,7 @@ pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
* to the value `t`.
*/
#[inline(always)]
pub pure fn from_elem<T:Copy,BT:Buildable<T>>(n_elts: uint,
t: T) -> BT {
pub fn from_elem<T:Copy,BT:Buildable<T>>(n_elts: uint, t: T) -> BT {
do Buildable::build_sized(n_elts) |push| {
let mut i: uint = 0;
while i < n_elts { push(t); i += 1; }
@@ -337,8 +325,8 @@ pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
/// Appends two generic sequences.
#[inline(always)]
pub pure fn append<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(
lhs: &IT, rhs: &IT) -> BT {
pub fn append<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(lhs: &IT, rhs: &IT)
-> BT {
let size_opt = lhs.size_hint().chain_ref(
|sz1| rhs.size_hint().map(|sz2| *sz1+*sz2));
do build_sized_opt(size_opt) |push| {
@@ -350,8 +338,7 @@ pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
/// Copies a generic sequence, possibly converting it to a different
/// type of sequence.
#[inline(always)]
pub pure fn copy_seq<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(
v: &IT) -> BT {
pub fn copy_seq<T:Copy,IT:BaseIter<T>,BT:Buildable<T>>(v: &IT) -> BT {
do build_sized_opt(v.size_hint()) |push| {
for v.each |x| { push(*x); }
}
+14 -14
View File
@@ -37,13 +37,13 @@ pub struct BoxRepr {
}
#[inline(always)]
pub pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
//! Determine if two shared boxes point to the same object
unsafe { ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) }
}
#[inline(always)]
pub pure fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
//! Determine if two mutable shared boxes point to the same object
unsafe { ptr::addr_of(&(*a)) == ptr::addr_of(&(*b)) }
}
@@ -51,41 +51,41 @@ pub struct BoxRepr {
#[cfg(notest)]
impl<T:Eq> Eq for @T {
#[inline(always)]
pure fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) }
fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) }
#[inline(always)]
pure fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) }
fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) }
}
#[cfg(notest)]
impl<T:Eq> Eq for @mut T {
#[inline(always)]
pure fn eq(&self, other: &@mut T) -> bool { *(*self) == *(*other) }
fn eq(&self, other: &@mut T) -> bool { *(*self) == *(*other) }
#[inline(always)]
pure fn ne(&self, other: &@mut T) -> bool { *(*self) != *(*other) }
fn ne(&self, other: &@mut T) -> bool { *(*self) != *(*other) }
}
#[cfg(notest)]
impl<T:Ord> Ord for @T {
#[inline(always)]
pure fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) }
fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) }
#[inline(always)]
pure fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) }
fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) }
#[inline(always)]
pure fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) }
fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) }
#[inline(always)]
pure fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) }
fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) }
}
#[cfg(notest)]
impl<T:Ord> Ord for @mut T {
#[inline(always)]
pure fn lt(&self, other: &@mut T) -> bool { *(*self) < *(*other) }
fn lt(&self, other: &@mut T) -> bool { *(*self) < *(*other) }
#[inline(always)]
pure fn le(&self, other: &@mut T) -> bool { *(*self) <= *(*other) }
fn le(&self, other: &@mut T) -> bool { *(*self) <= *(*other) }
#[inline(always)]
pure fn ge(&self, other: &@mut T) -> bool { *(*self) >= *(*other) }
fn ge(&self, other: &@mut T) -> bool { *(*self) >= *(*other) }
#[inline(always)]
pure fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
}
#[test]
+1 -1
View File
@@ -55,7 +55,7 @@ fn borrow_mut<R>(&self, op: &fn(t: &mut T) -> R) -> R {
}
}
pure fn borrow_const<R>(&self, op: &fn(t: &const T) -> R) -> R {
fn borrow_const<R>(&self, op: &fn(t: &const T) -> R) -> R {
op(&const self.value)
}
+7 -7
View File
@@ -20,25 +20,25 @@
#[cfg(notest)]
impl Eq for () {
#[inline(always)]
pure fn eq(&self, _other: &()) -> bool { true }
fn eq(&self, _other: &()) -> bool { true }
#[inline(always)]
pure fn ne(&self, _other: &()) -> bool { false }
fn ne(&self, _other: &()) -> bool { false }
}
#[cfg(notest)]
impl Ord for () {
#[inline(always)]
pure fn lt(&self, _other: &()) -> bool { false }
fn lt(&self, _other: &()) -> bool { false }
#[inline(always)]
pure fn le(&self, _other: &()) -> bool { true }
fn le(&self, _other: &()) -> bool { true }
#[inline(always)]
pure fn ge(&self, _other: &()) -> bool { true }
fn ge(&self, _other: &()) -> bool { true }
#[inline(always)]
pure fn gt(&self, _other: &()) -> bool { false }
fn gt(&self, _other: &()) -> bool { false }
}
#[cfg(notest)]
impl TotalOrd for () {
#[inline(always)]
pure fn cmp(&self, _other: &()) -> Ordering { Equal }
fn cmp(&self, _other: &()) -> Ordering { Equal }
}
+72 -70
View File
@@ -33,7 +33,7 @@ fn $name:ident(
),*
) -> $rv:ty = $bound_name:path
) => (
pub pure fn $name($( $arg : $arg_ty ),*) -> $rv {
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
}
@@ -109,57 +109,59 @@ fn $name:ident(
pub const neg_infinity: f32 = -1.0_f32/0.0_f32;
#[inline(always)]
pub pure fn is_NaN(f: f32) -> bool { f != f }
pub fn is_NaN(f: f32) -> bool { f != f }
#[inline(always)]
pub pure fn add(x: f32, y: f32) -> f32 { return x + y; }
pub fn add(x: f32, y: f32) -> f32 { return x + y; }
#[inline(always)]
pub pure fn sub(x: f32, y: f32) -> f32 { return x - y; }
pub fn sub(x: f32, y: f32) -> f32 { return x - y; }
#[inline(always)]
pub pure fn mul(x: f32, y: f32) -> f32 { return x * y; }
pub fn mul(x: f32, y: f32) -> f32 { return x * y; }
#[inline(always)]
pub pure fn div(x: f32, y: f32) -> f32 { return x / y; }
pub fn div(x: f32, y: f32) -> f32 { return x / y; }
#[inline(always)]
pub pure fn rem(x: f32, y: f32) -> f32 { return x % y; }
pub fn rem(x: f32, y: f32) -> f32 { return x % y; }
#[inline(always)]
pub pure fn lt(x: f32, y: f32) -> bool { return x < y; }
pub fn lt(x: f32, y: f32) -> bool { return x < y; }
#[inline(always)]
pub pure fn le(x: f32, y: f32) -> bool { return x <= y; }
pub fn le(x: f32, y: f32) -> bool { return x <= y; }
#[inline(always)]
pub pure fn eq(x: f32, y: f32) -> bool { return x == y; }
pub fn eq(x: f32, y: f32) -> bool { return x == y; }
#[inline(always)]
pub pure fn ne(x: f32, y: f32) -> bool { return x != y; }
pub fn ne(x: f32, y: f32) -> bool { return x != y; }
#[inline(always)]
pub pure fn ge(x: f32, y: f32) -> bool { return x >= y; }
pub fn ge(x: f32, y: f32) -> bool { return x >= y; }
#[inline(always)]
pub pure fn gt(x: f32, y: f32) -> bool { return x > y; }
pub fn gt(x: f32, y: f32) -> bool { return x > y; }
/// Returns `x` rounded down
#[inline(always)]
pub pure fn floor(x: f32) -> f32 { unsafe { floorf32(x) } }
pub fn floor(x: f32) -> f32 { unsafe { floorf32(x) } }
// FIXME (#1999): replace the predicates below with llvm intrinsics or
// calls to the libmath macros in the rust runtime for performance.
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
#[inline(always)]
pub pure fn is_positive(x: f32) -> bool
{ return x > 0.0f32 || (1.0f32/x) == infinity; }
pub fn is_positive(x: f32) -> bool {
x > 0.0f32 || (1.0f32/x) == infinity
}
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
#[inline(always)]
pub pure fn is_negative(x: f32) -> bool
{ return x < 0.0f32 || (1.0f32/x) == neg_infinity; }
pub fn is_negative(x: f32) -> bool {
x < 0.0f32 || (1.0f32/x) == neg_infinity
}
/**
* Returns true if `x` is a negative number, including -0.0f320 and -Infinity
@@ -167,7 +169,7 @@ fn $name:ident(
* This is the same as `f32::is_negative`.
*/
#[inline(always)]
pub pure fn is_nonpositive(x: f32) -> bool {
pub fn is_nonpositive(x: f32) -> bool {
return x < 0.0f32 || (1.0f32/x) == neg_infinity;
}
@@ -177,25 +179,25 @@ fn $name:ident(
* This is the same as `f32::is_positive`.)
*/
#[inline(always)]
pub pure fn is_nonnegative(x: f32) -> bool {
pub fn is_nonnegative(x: f32) -> bool {
return x > 0.0f32 || (1.0f32/x) == infinity;
}
/// Returns true if `x` is a zero number (positive or negative zero)
#[inline(always)]
pub pure fn is_zero(x: f32) -> bool {
pub fn is_zero(x: f32) -> bool {
return x == 0.0f32 || x == -0.0f32;
}
/// Returns true if `x`is an infinite number
#[inline(always)]
pub pure fn is_infinite(x: f32) -> bool {
pub fn is_infinite(x: f32) -> bool {
return x == infinity || x == neg_infinity;
}
/// Returns true if `x`is a finite number
#[inline(always)]
pub pure fn is_finite(x: f32) -> bool {
pub fn is_finite(x: f32) -> bool {
return !(is_NaN(x) || is_infinite(x));
}
@@ -246,43 +248,43 @@ pub mod consts {
}
#[inline(always)]
pub pure fn signbit(x: f32) -> int {
pub fn signbit(x: f32) -> int {
if is_negative(x) { return 1; } else { return 0; }
}
#[inline(always)]
pub pure fn logarithm(n: f32, b: f32) -> f32 {
pub fn logarithm(n: f32, b: f32) -> f32 {
return log2(n) / log2(b);
}
#[cfg(notest)]
impl cmp::Eq for f32 {
#[inline(always)]
pure fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
#[inline(always)]
pure fn ne(&self, other: &f32) -> bool { (*self) != (*other) }
fn ne(&self, other: &f32) -> bool { (*self) != (*other) }
}
#[cfg(notest)]
impl cmp::Ord for f32 {
#[inline(always)]
pure fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
#[inline(always)]
pure fn le(&self, other: &f32) -> bool { (*self) <= (*other) }
fn le(&self, other: &f32) -> bool { (*self) <= (*other) }
#[inline(always)]
pure fn ge(&self, other: &f32) -> bool { (*self) >= (*other) }
fn ge(&self, other: &f32) -> bool { (*self) >= (*other) }
#[inline(always)]
pure fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
}
impl num::Zero for f32 {
#[inline(always)]
pure fn zero() -> f32 { 0.0 }
fn zero() -> f32 { 0.0 }
}
impl num::One for f32 {
#[inline(always)]
pure fn one() -> f32 { 1.0 }
fn one() -> f32 { 1.0 }
}
impl NumCast for f32 {
@@ -290,53 +292,53 @@ impl NumCast for f32 {
* Cast `n` to an `f32`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> f32 { n.to_f32() }
fn from<N:NumCast>(n: N) -> f32 { n.to_f32() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[cfg(notest)]
impl ops::Add<f32,f32> for f32 {
pure fn add(&self, other: &f32) -> f32 { *self + *other }
fn add(&self, other: &f32) -> f32 { *self + *other }
}
#[cfg(notest)]
impl ops::Sub<f32,f32> for f32 {
pure fn sub(&self, other: &f32) -> f32 { *self - *other }
fn sub(&self, other: &f32) -> f32 { *self - *other }
}
#[cfg(notest)]
impl ops::Mul<f32,f32> for f32 {
pure fn mul(&self, other: &f32) -> f32 { *self * *other }
fn mul(&self, other: &f32) -> f32 { *self * *other }
}
#[cfg(notest)]
impl ops::Div<f32,f32> for f32 {
pure fn div(&self, other: &f32) -> f32 { *self / *other }
fn div(&self, other: &f32) -> f32 { *self / *other }
}
#[cfg(notest)]
impl ops::Modulo<f32,f32> for f32 {
pure fn modulo(&self, other: &f32) -> f32 { *self % *other }
fn modulo(&self, other: &f32) -> f32 { *self % *other }
}
#[cfg(notest)]
impl ops::Neg<f32> for f32 {
pure fn neg(&self) -> f32 { -*self }
fn neg(&self) -> f32 { -*self }
}
impl num::Round for f32 {
#[inline(always)]
pure fn round(&self, mode: num::RoundMode) -> f32 {
fn round(&self, mode: num::RoundMode) -> f32 {
match mode {
num::RoundDown => floor(*self),
num::RoundUp => ceil(*self),
@@ -348,11 +350,11 @@ impl num::Round for f32 {
}
#[inline(always)]
pure fn floor(&self) -> f32 { floor(*self) }
fn floor(&self) -> f32 { floor(*self) }
#[inline(always)]
pure fn ceil(&self) -> f32 { ceil(*self) }
fn ceil(&self) -> f32 { ceil(*self) }
#[inline(always)]
pure fn fract(&self) -> f32 {
fn fract(&self) -> f32 {
if is_negative(*self) {
(*self) - ceil(*self)
} else {
@@ -373,7 +375,7 @@ impl num::Round for f32 {
* * num - The float value
*/
#[inline(always)]
pub pure fn to_str(num: f32) -> ~str {
pub fn to_str(num: f32) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
r
@@ -387,7 +389,7 @@ impl num::Round for f32 {
* * num - The float value
*/
#[inline(always)]
pub pure fn to_str_hex(num: f32) -> ~str {
pub fn to_str_hex(num: f32) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
r
@@ -408,7 +410,7 @@ impl num::Round for f32 {
* are expected, use `to_str_radix_special()` instead.
*/
#[inline(always)]
pub pure fn to_str_radix(num: f32, rdx: uint) -> ~str {
pub fn to_str_radix(num: f32, rdx: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
@@ -426,7 +428,7 @@ impl num::Round for f32 {
* * radix - The base to use
*/
#[inline(always)]
pub pure fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
pub fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
strconv::to_str_common(&num, rdx, true,
strconv::SignNeg, strconv::DigAll)
}
@@ -441,7 +443,7 @@ impl num::Round for f32 {
* * digits - The number of significant digits
*/
#[inline(always)]
pub pure fn to_str_exact(num: f32, dig: uint) -> ~str {
pub fn to_str_exact(num: f32, dig: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigExact(dig));
r
@@ -457,7 +459,7 @@ impl num::Round for f32 {
* * digits - The number of significant digits
*/
#[inline(always)]
pub pure fn to_str_digits(num: f32, dig: uint) -> ~str {
pub fn to_str_digits(num: f32, dig: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigMax(dig));
r
@@ -465,12 +467,12 @@ impl num::Round for f32 {
impl to_str::ToStr for f32 {
#[inline(always)]
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
}
impl num::ToStrRadix for f32 {
#[inline(always)]
pure fn to_str_radix(&self, rdx: uint) -> ~str {
fn to_str_radix(&self, rdx: uint) -> ~str {
to_str_radix(*self, rdx)
}
}
@@ -503,7 +505,7 @@ impl num::ToStrRadix for f32 {
* `Some(n)` where `n` is the floating-point number represented by `num`.
*/
#[inline(always)]
pub pure fn from_str(num: &str) -> Option<f32> {
pub fn from_str(num: &str) -> Option<f32> {
strconv::from_str_common(num, 10u, true, true, true,
strconv::ExpDec, false)
}
@@ -536,7 +538,7 @@ impl num::ToStrRadix for f32 {
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
*/
#[inline(always)]
pub pure fn from_str_hex(num: &str) -> Option<f32> {
pub fn from_str_hex(num: &str) -> Option<f32> {
strconv::from_str_common(num, 16u, true, true, true,
strconv::ExpBin, false)
}
@@ -561,19 +563,19 @@ impl num::ToStrRadix for f32 {
* `Some(n)` where `n` is the floating-point number represented by `num`.
*/
#[inline(always)]
pub pure fn from_str_radix(num: &str, rdx: uint) -> Option<f32> {
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f32> {
strconv::from_str_common(num, rdx, true, true, false,
strconv::ExpNone, false)
}
impl from_str::FromStr for f32 {
#[inline(always)]
pure fn from_str(val: &str) -> Option<f32> { from_str(val) }
fn from_str(val: &str) -> Option<f32> { from_str(val) }
}
impl num::FromStrRadix for f32 {
#[inline(always)]
pure fn from_str_radix(val: &str, rdx: uint) -> Option<f32> {
fn from_str_radix(val: &str, rdx: uint) -> Option<f32> {
from_str_radix(val, rdx)
}
}
+68 -68
View File
@@ -34,7 +34,7 @@ fn $name:ident(
),*
) -> $rv:ty = $bound_name:path
) => (
pub pure fn $name($( $arg : $arg_ty ),*) -> $rv {
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
}
@@ -136,49 +136,49 @@ fn $name:ident(
pub const neg_infinity: f64 = -1.0_f64/0.0_f64;
#[inline(always)]
pub pure fn is_NaN(f: f64) -> bool { f != f }
pub fn is_NaN(f: f64) -> bool { f != f }
#[inline(always)]
pub pure fn add(x: f64, y: f64) -> f64 { return x + y; }
pub fn add(x: f64, y: f64) -> f64 { return x + y; }
#[inline(always)]
pub pure fn sub(x: f64, y: f64) -> f64 { return x - y; }
pub fn sub(x: f64, y: f64) -> f64 { return x - y; }
#[inline(always)]
pub pure fn mul(x: f64, y: f64) -> f64 { return x * y; }
pub fn mul(x: f64, y: f64) -> f64 { return x * y; }
#[inline(always)]
pub pure fn div(x: f64, y: f64) -> f64 { return x / y; }
pub fn div(x: f64, y: f64) -> f64 { return x / y; }
#[inline(always)]
pub pure fn rem(x: f64, y: f64) -> f64 { return x % y; }
pub fn rem(x: f64, y: f64) -> f64 { return x % y; }
#[inline(always)]
pub pure fn lt(x: f64, y: f64) -> bool { return x < y; }
pub fn lt(x: f64, y: f64) -> bool { return x < y; }
#[inline(always)]
pub pure fn le(x: f64, y: f64) -> bool { return x <= y; }
pub fn le(x: f64, y: f64) -> bool { return x <= y; }
#[inline(always)]
pub pure fn eq(x: f64, y: f64) -> bool { return x == y; }
pub fn eq(x: f64, y: f64) -> bool { return x == y; }
#[inline(always)]
pub pure fn ne(x: f64, y: f64) -> bool { return x != y; }
pub fn ne(x: f64, y: f64) -> bool { return x != y; }
#[inline(always)]
pub pure fn ge(x: f64, y: f64) -> bool { return x >= y; }
pub fn ge(x: f64, y: f64) -> bool { return x >= y; }
#[inline(always)]
pub pure fn gt(x: f64, y: f64) -> bool { return x > y; }
pub fn gt(x: f64, y: f64) -> bool { return x > y; }
/// Returns true if `x` is a positive number, including +0.0f640 and +Infinity
#[inline(always)]
pub pure fn is_positive(x: f64) -> bool
pub fn is_positive(x: f64) -> bool
{ return x > 0.0f64 || (1.0f64/x) == infinity; }
/// Returns true if `x` is a negative number, including -0.0f640 and -Infinity
#[inline(always)]
pub pure fn is_negative(x: f64) -> bool
pub fn is_negative(x: f64) -> bool
{ return x < 0.0f64 || (1.0f64/x) == neg_infinity; }
/**
@@ -187,7 +187,7 @@ fn $name:ident(
* This is the same as `f64::is_negative`.
*/
#[inline(always)]
pub pure fn is_nonpositive(x: f64) -> bool {
pub fn is_nonpositive(x: f64) -> bool {
return x < 0.0f64 || (1.0f64/x) == neg_infinity;
}
@@ -197,31 +197,31 @@ fn $name:ident(
* This is the same as `f64::positive`.
*/
#[inline(always)]
pub pure fn is_nonnegative(x: f64) -> bool {
pub fn is_nonnegative(x: f64) -> bool {
return x > 0.0f64 || (1.0f64/x) == infinity;
}
/// Returns true if `x` is a zero number (positive or negative zero)
#[inline(always)]
pub pure fn is_zero(x: f64) -> bool {
pub fn is_zero(x: f64) -> bool {
return x == 0.0f64 || x == -0.0f64;
}
/// Returns true if `x`is an infinite number
#[inline(always)]
pub pure fn is_infinite(x: f64) -> bool {
pub fn is_infinite(x: f64) -> bool {
return x == infinity || x == neg_infinity;
}
/// Returns true if `x` is a finite number
#[inline(always)]
pub pure fn is_finite(x: f64) -> bool {
pub fn is_finite(x: f64) -> bool {
return !(is_NaN(x) || is_infinite(x));
}
/// Returns `x` rounded down
#[inline(always)]
pub pure fn floor(x: f64) -> f64 { unsafe { floorf64(x) } }
pub fn floor(x: f64) -> f64 { unsafe { floorf64(x) } }
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify
@@ -270,33 +270,33 @@ pub mod consts {
}
#[inline(always)]
pub pure fn signbit(x: f64) -> int {
pub fn signbit(x: f64) -> int {
if is_negative(x) { return 1; } else { return 0; }
}
#[inline(always)]
pub pure fn logarithm(n: f64, b: f64) -> f64 {
pub fn logarithm(n: f64, b: f64) -> f64 {
return log2(n) / log2(b);
}
#[cfg(notest)]
impl cmp::Eq for f64 {
#[inline(always)]
pure fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
#[inline(always)]
pure fn ne(&self, other: &f64) -> bool { (*self) != (*other) }
fn ne(&self, other: &f64) -> bool { (*self) != (*other) }
}
#[cfg(notest)]
impl cmp::Ord for f64 {
#[inline(always)]
pure fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
#[inline(always)]
pure fn le(&self, other: &f64) -> bool { (*self) <= (*other) }
fn le(&self, other: &f64) -> bool { (*self) <= (*other) }
#[inline(always)]
pure fn ge(&self, other: &f64) -> bool { (*self) >= (*other) }
fn ge(&self, other: &f64) -> bool { (*self) >= (*other) }
#[inline(always)]
pure fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
}
impl NumCast for f64 {
@@ -304,63 +304,63 @@ impl NumCast for f64 {
* Cast `n` to an `f64`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> f64 { n.to_f64() }
fn from<N:NumCast>(n: N) -> f64 { n.to_f64() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
impl num::Zero for f64 {
#[inline(always)]
pure fn zero() -> f64 { 0.0 }
fn zero() -> f64 { 0.0 }
}
impl num::One for f64 {
#[inline(always)]
pure fn one() -> f64 { 1.0 }
fn one() -> f64 { 1.0 }
}
#[cfg(notest)]
impl ops::Add<f64,f64> for f64 {
pure fn add(&self, other: &f64) -> f64 { *self + *other }
fn add(&self, other: &f64) -> f64 { *self + *other }
}
#[cfg(notest)]
impl ops::Sub<f64,f64> for f64 {
pure fn sub(&self, other: &f64) -> f64 { *self - *other }
fn sub(&self, other: &f64) -> f64 { *self - *other }
}
#[cfg(notest)]
impl ops::Mul<f64,f64> for f64 {
pure fn mul(&self, other: &f64) -> f64 { *self * *other }
fn mul(&self, other: &f64) -> f64 { *self * *other }
}
#[cfg(notest)]
impl ops::Div<f64,f64> for f64 {
pure fn div(&self, other: &f64) -> f64 { *self / *other }
fn div(&self, other: &f64) -> f64 { *self / *other }
}
#[cfg(notest)]
impl ops::Modulo<f64,f64> for f64 {
pure fn modulo(&self, other: &f64) -> f64 { *self % *other }
fn modulo(&self, other: &f64) -> f64 { *self % *other }
}
#[cfg(notest)]
impl ops::Neg<f64> for f64 {
pure fn neg(&self) -> f64 { -*self }
fn neg(&self) -> f64 { -*self }
}
impl num::Round for f64 {
#[inline(always)]
pure fn round(&self, mode: num::RoundMode) -> f64 {
fn round(&self, mode: num::RoundMode) -> f64 {
match mode {
num::RoundDown => floor(*self),
num::RoundUp => ceil(*self),
@@ -372,11 +372,11 @@ impl num::Round for f64 {
}
#[inline(always)]
pure fn floor(&self) -> f64 { floor(*self) }
fn floor(&self) -> f64 { floor(*self) }
#[inline(always)]
pure fn ceil(&self) -> f64 { ceil(*self) }
fn ceil(&self) -> f64 { ceil(*self) }
#[inline(always)]
pure fn fract(&self) -> f64 {
fn fract(&self) -> f64 {
if is_negative(*self) {
(*self) - ceil(*self)
} else {
@@ -397,7 +397,7 @@ impl num::Round for f64 {
* * num - The float value
*/
#[inline(always)]
pub pure fn to_str(num: f64) -> ~str {
pub fn to_str(num: f64) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
r
@@ -411,7 +411,7 @@ impl num::Round for f64 {
* * num - The float value
*/
#[inline(always)]
pub pure fn to_str_hex(num: f64) -> ~str {
pub fn to_str_hex(num: f64) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
r
@@ -432,7 +432,7 @@ impl num::Round for f64 {
* are expected, use `to_str_radix_special()` instead.
*/
#[inline(always)]
pub pure fn to_str_radix(num: f64, rdx: uint) -> ~str {
pub fn to_str_radix(num: f64, rdx: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
@@ -450,7 +450,7 @@ impl num::Round for f64 {
* * radix - The base to use
*/
#[inline(always)]
pub pure fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
pub fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
strconv::to_str_common(&num, rdx, true,
strconv::SignNeg, strconv::DigAll)
}
@@ -465,7 +465,7 @@ impl num::Round for f64 {
* * digits - The number of significant digits
*/
#[inline(always)]
pub pure fn to_str_exact(num: f64, dig: uint) -> ~str {
pub fn to_str_exact(num: f64, dig: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigExact(dig));
r
@@ -481,7 +481,7 @@ impl num::Round for f64 {
* * digits - The number of significant digits
*/
#[inline(always)]
pub pure fn to_str_digits(num: f64, dig: uint) -> ~str {
pub fn to_str_digits(num: f64, dig: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigMax(dig));
r
@@ -489,12 +489,12 @@ impl num::Round for f64 {
impl to_str::ToStr for f64 {
#[inline(always)]
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
}
impl num::ToStrRadix for f64 {
#[inline(always)]
pure fn to_str_radix(&self, rdx: uint) -> ~str {
fn to_str_radix(&self, rdx: uint) -> ~str {
to_str_radix(*self, rdx)
}
}
@@ -527,7 +527,7 @@ impl num::ToStrRadix for f64 {
* `Some(n)` where `n` is the floating-point number represented by `num`.
*/
#[inline(always)]
pub pure fn from_str(num: &str) -> Option<f64> {
pub fn from_str(num: &str) -> Option<f64> {
strconv::from_str_common(num, 10u, true, true, true,
strconv::ExpDec, false)
}
@@ -560,7 +560,7 @@ impl num::ToStrRadix for f64 {
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
*/
#[inline(always)]
pub pure fn from_str_hex(num: &str) -> Option<f64> {
pub fn from_str_hex(num: &str) -> Option<f64> {
strconv::from_str_common(num, 16u, true, true, true,
strconv::ExpBin, false)
}
@@ -585,19 +585,19 @@ impl num::ToStrRadix for f64 {
* `Some(n)` where `n` is the floating-point number represented by `num`.
*/
#[inline(always)]
pub pure fn from_str_radix(num: &str, rdx: uint) -> Option<f64> {
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f64> {
strconv::from_str_common(num, rdx, true, true, false,
strconv::ExpNone, false)
}
impl from_str::FromStr for f64 {
#[inline(always)]
pure fn from_str(val: &str) -> Option<f64> { from_str(val) }
fn from_str(val: &str) -> Option<f64> { from_str(val) }
}
impl num::FromStrRadix for f64 {
#[inline(always)]
pure fn from_str_radix(val: &str, rdx: uint) -> Option<f64> {
fn from_str_radix(val: &str, rdx: uint) -> Option<f64> {
from_str_radix(val, rdx)
}
}
+60 -60
View File
@@ -103,7 +103,7 @@ pub mod consts {
* * num - The float value
*/
#[inline(always)]
pub pure fn to_str(num: float) -> ~str {
pub fn to_str(num: float) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
r
@@ -117,7 +117,7 @@ pub mod consts {
* * num - The float value
*/
#[inline(always)]
pub pure fn to_str_hex(num: float) -> ~str {
pub fn to_str_hex(num: float) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
r
@@ -138,7 +138,7 @@ pub mod consts {
* are expected, use `to_str_radix_special()` instead.
*/
#[inline(always)]
pub pure fn to_str_radix(num: float, radix: uint) -> ~str {
pub fn to_str_radix(num: float, radix: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, radix, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
@@ -156,7 +156,7 @@ pub mod consts {
* * radix - The base to use
*/
#[inline(always)]
pub pure fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
pub fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
strconv::to_str_common(&num, radix, true,
strconv::SignNeg, strconv::DigAll)
}
@@ -171,7 +171,7 @@ pub mod consts {
* * digits - The number of significant digits
*/
#[inline(always)]
pub pure fn to_str_exact(num: float, digits: uint) -> ~str {
pub fn to_str_exact(num: float, digits: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigExact(digits));
r
@@ -193,7 +193,7 @@ pub fn test_to_str_exact_do_decimal() {
* * digits - The number of significant digits
*/
#[inline(always)]
pub pure fn to_str_digits(num: float, digits: uint) -> ~str {
pub fn to_str_digits(num: float, digits: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, strconv::SignNeg, strconv::DigMax(digits));
r
@@ -201,12 +201,12 @@ pub fn test_to_str_exact_do_decimal() {
impl to_str::ToStr for float {
#[inline(always)]
pure fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
fn to_str(&self) -> ~str { to_str_digits(*self, 8) }
}
impl num::ToStrRadix for float {
#[inline(always)]
pure fn to_str_radix(&self, radix: uint) -> ~str {
fn to_str_radix(&self, radix: uint) -> ~str {
to_str_radix(*self, radix)
}
}
@@ -239,7 +239,7 @@ impl num::ToStrRadix for float {
* `Some(n)` where `n` is the floating-point number represented by `num`.
*/
#[inline(always)]
pub pure fn from_str(num: &str) -> Option<float> {
pub fn from_str(num: &str) -> Option<float> {
strconv::from_str_common(num, 10u, true, true, true,
strconv::ExpDec, false)
}
@@ -272,7 +272,7 @@ impl num::ToStrRadix for float {
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
*/
#[inline(always)]
pub pure fn from_str_hex(num: &str) -> Option<float> {
pub fn from_str_hex(num: &str) -> Option<float> {
strconv::from_str_common(num, 16u, true, true, true,
strconv::ExpBin, false)
}
@@ -297,19 +297,19 @@ impl num::ToStrRadix for float {
* `Some(n)` where `n` is the floating-point number represented by `num`.
*/
#[inline(always)]
pub pure fn from_str_radix(num: &str, radix: uint) -> Option<float> {
pub fn from_str_radix(num: &str, radix: uint) -> Option<float> {
strconv::from_str_common(num, radix, true, true, false,
strconv::ExpNone, false)
}
impl from_str::FromStr for float {
#[inline(always)]
pure fn from_str(val: &str) -> Option<float> { from_str(val) }
fn from_str(val: &str) -> Option<float> { from_str(val) }
}
impl num::FromStrRadix for float {
#[inline(always)]
pure fn from_str_radix(val: &str, radix: uint) -> Option<float> {
fn from_str_radix(val: &str, radix: uint) -> Option<float> {
from_str_radix(val, radix)
}
}
@@ -330,7 +330,7 @@ impl num::FromStrRadix for float {
*
* `NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
*/
pub pure fn pow_with_uint(base: uint, pow: uint) -> float {
pub fn pow_with_uint(base: uint, pow: uint) -> float {
if base == 0u {
if pow == 0u {
return NaN as float;
@@ -351,69 +351,69 @@ impl num::FromStrRadix for float {
}
#[inline(always)]
pub pure fn is_positive(x: float) -> bool { f64::is_positive(x as f64) }
pub fn is_positive(x: float) -> bool { f64::is_positive(x as f64) }
#[inline(always)]
pub pure fn is_negative(x: float) -> bool { f64::is_negative(x as f64) }
pub fn is_negative(x: float) -> bool { f64::is_negative(x as f64) }
#[inline(always)]
pub pure fn is_nonpositive(x: float) -> bool { f64::is_nonpositive(x as f64) }
pub fn is_nonpositive(x: float) -> bool { f64::is_nonpositive(x as f64) }
#[inline(always)]
pub pure fn is_nonnegative(x: float) -> bool { f64::is_nonnegative(x as f64) }
pub fn is_nonnegative(x: float) -> bool { f64::is_nonnegative(x as f64) }
#[inline(always)]
pub pure fn is_zero(x: float) -> bool { f64::is_zero(x as f64) }
pub fn is_zero(x: float) -> bool { f64::is_zero(x as f64) }
#[inline(always)]
pub pure fn is_infinite(x: float) -> bool { f64::is_infinite(x as f64) }
pub fn is_infinite(x: float) -> bool { f64::is_infinite(x as f64) }
#[inline(always)]
pub pure fn is_finite(x: float) -> bool { f64::is_finite(x as f64) }
pub fn is_finite(x: float) -> bool { f64::is_finite(x as f64) }
#[inline(always)]
pub pure fn is_NaN(x: float) -> bool { f64::is_NaN(x as f64) }
pub fn is_NaN(x: float) -> bool { f64::is_NaN(x as f64) }
#[inline(always)]
pub pure fn abs(x: float) -> float {
pub fn abs(x: float) -> float {
unsafe { f64::abs(x as f64) as float }
}
#[inline(always)]
pub pure fn sqrt(x: float) -> float {
pub fn sqrt(x: float) -> float {
unsafe { f64::sqrt(x as f64) as float }
}
#[inline(always)]
pub pure fn atan(x: float) -> float {
pub fn atan(x: float) -> float {
unsafe { f64::atan(x as f64) as float }
}
#[inline(always)]
pub pure fn sin(x: float) -> float {
pub fn sin(x: float) -> float {
unsafe { f64::sin(x as f64) as float }
}
#[inline(always)]
pub pure fn cos(x: float) -> float {
pub fn cos(x: float) -> float {
unsafe { f64::cos(x as f64) as float }
}
#[inline(always)]
pub pure fn tan(x: float) -> float {
pub fn tan(x: float) -> float {
unsafe { f64::tan(x as f64) as float }
}
#[cfg(notest)]
impl Eq for float {
pure fn eq(&self, other: &float) -> bool { (*self) == (*other) }
pure fn ne(&self, other: &float) -> bool { (*self) != (*other) }
fn eq(&self, other: &float) -> bool { (*self) == (*other) }
fn ne(&self, other: &float) -> bool { (*self) != (*other) }
}
#[cfg(notest)]
impl Ord for float {
pure fn lt(&self, other: &float) -> bool { (*self) < (*other) }
pure fn le(&self, other: &float) -> bool { (*self) <= (*other) }
pure fn ge(&self, other: &float) -> bool { (*self) >= (*other) }
pure fn gt(&self, other: &float) -> bool { (*self) > (*other) }
fn lt(&self, other: &float) -> bool { (*self) < (*other) }
fn le(&self, other: &float) -> bool { (*self) <= (*other) }
fn ge(&self, other: &float) -> bool { (*self) >= (*other) }
fn gt(&self, other: &float) -> bool { (*self) > (*other) }
}
impl num::Zero for float {
#[inline(always)]
pure fn zero() -> float { 0.0 }
fn zero() -> float { 0.0 }
}
impl num::One for float {
#[inline(always)]
pure fn one() -> float { 1.0 }
fn one() -> float { 1.0 }
}
impl NumCast for float {
@@ -421,28 +421,28 @@ impl NumCast for float {
* Cast `n` to a `float`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> float { n.to_float() }
fn from<N:NumCast>(n: N) -> float { n.to_float() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self }
}
impl num::Round for float {
#[inline(always)]
pure fn round(&self, mode: num::RoundMode) -> float {
fn round(&self, mode: num::RoundMode) -> float {
match mode {
num::RoundDown
=> f64::floor(*self as f64) as float,
@@ -460,11 +460,11 @@ impl num::Round for float {
}
#[inline(always)]
pure fn floor(&self) -> float { f64::floor(*self as f64) as float}
fn floor(&self) -> float { f64::floor(*self as f64) as float}
#[inline(always)]
pure fn ceil(&self) -> float { f64::ceil(*self as f64) as float}
fn ceil(&self) -> float { f64::ceil(*self as f64) as float}
#[inline(always)]
pure fn fract(&self) -> float {
fn fract(&self) -> float {
if is_negative(*self) {
(*self) - (f64::ceil(*self as f64) as float)
} else {
@@ -475,27 +475,27 @@ impl num::Round for float {
#[cfg(notest)]
impl ops::Add<float,float> for float {
pure fn add(&self, other: &float) -> float { *self + *other }
fn add(&self, other: &float) -> float { *self + *other }
}
#[cfg(notest)]
impl ops::Sub<float,float> for float {
pure fn sub(&self, other: &float) -> float { *self - *other }
fn sub(&self, other: &float) -> float { *self - *other }
}
#[cfg(notest)]
impl ops::Mul<float,float> for float {
pure fn mul(&self, other: &float) -> float { *self * *other }
fn mul(&self, other: &float) -> float { *self * *other }
}
#[cfg(notest)]
impl ops::Div<float,float> for float {
pure fn div(&self, other: &float) -> float { *self / *other }
fn div(&self, other: &float) -> float { *self / *other }
}
#[cfg(notest)]
impl ops::Modulo<float,float> for float {
pure fn modulo(&self, other: &float) -> float { *self % *other }
fn modulo(&self, other: &float) -> float { *self % *other }
}
#[cfg(notest)]
impl ops::Neg<float> for float {
pure fn neg(&self) -> float { -*self }
fn neg(&self) -> float { -*self }
}
#[test]
+44 -44
View File
@@ -28,13 +28,13 @@
pub const max_value: T = min_value - 1 as T;
#[inline(always)]
pub pure fn add(x: T, y: T) -> T { x + y }
pub fn add(x: T, y: T) -> T { x + y }
#[inline(always)]
pub pure fn sub(x: T, y: T) -> T { x - y }
pub fn sub(x: T, y: T) -> T { x - y }
#[inline(always)]
pub pure fn mul(x: T, y: T) -> T { x * y }
pub fn mul(x: T, y: T) -> T { x * y }
#[inline(always)]
pub pure fn div(x: T, y: T) -> T { x / y }
pub fn div(x: T, y: T) -> T { x / y }
/**
* Returns the remainder of y / x.
@@ -57,29 +57,29 @@
*
*/
#[inline(always)]
pub pure fn rem(x: T, y: T) -> T { x % y }
pub fn rem(x: T, y: T) -> T { x % y }
#[inline(always)]
pub pure fn lt(x: T, y: T) -> bool { x < y }
pub fn lt(x: T, y: T) -> bool { x < y }
#[inline(always)]
pub pure fn le(x: T, y: T) -> bool { x <= y }
pub fn le(x: T, y: T) -> bool { x <= y }
#[inline(always)]
pub pure fn eq(x: T, y: T) -> bool { x == y }
pub fn eq(x: T, y: T) -> bool { x == y }
#[inline(always)]
pub pure fn ne(x: T, y: T) -> bool { x != y }
pub fn ne(x: T, y: T) -> bool { x != y }
#[inline(always)]
pub pure fn ge(x: T, y: T) -> bool { x >= y }
pub fn ge(x: T, y: T) -> bool { x >= y }
#[inline(always)]
pub pure fn gt(x: T, y: T) -> bool { x > y }
pub fn gt(x: T, y: T) -> bool { x > y }
#[inline(always)]
pub pure fn is_positive(x: T) -> bool { x > 0 as T }
pub fn is_positive(x: T) -> bool { x > 0 as T }
#[inline(always)]
pub pure fn is_negative(x: T) -> bool { x < 0 as T }
pub fn is_negative(x: T) -> bool { x < 0 as T }
#[inline(always)]
pub pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
pub fn is_nonpositive(x: T) -> bool { x <= 0 as T }
#[inline(always)]
pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
pub fn is_nonnegative(x: T) -> bool { x >= 0 as T }
/**
* Iterate over the range [`lo`..`hi`)
@@ -100,7 +100,7 @@
*/
#[inline(always)]
/// Iterate over the range [`start`,`start`+`step`..`stop`)
pub pure fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
pub fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
let mut i = start;
if step == 0 {
fail!(~"range_step called with step == 0");
@@ -119,116 +119,116 @@
#[inline(always)]
/// Iterate over the range [`lo`..`hi`)
pub pure fn range(lo: T, hi: T, it: &fn(T) -> bool) {
pub fn range(lo: T, hi: T, it: &fn(T) -> bool) {
range_step(lo, hi, 1 as T, it);
}
#[inline(always)]
/// Iterate over the range [`hi`..`lo`)
pub pure fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
pub fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
range_step(hi, lo, -1 as T, it);
}
/// Computes the bitwise complement
#[inline(always)]
pub pure fn compl(i: T) -> T {
pub fn compl(i: T) -> T {
-1 as T ^ i
}
/// Computes the absolute value
#[inline(always)]
pub pure fn abs(i: T) -> T {
pub fn abs(i: T) -> T {
if is_negative(i) { -i } else { i }
}
#[cfg(notest)]
impl Ord for T {
#[inline(always)]
pure fn lt(&self, other: &T) -> bool { return (*self) < (*other); }
fn lt(&self, other: &T) -> bool { return (*self) < (*other); }
#[inline(always)]
pure fn le(&self, other: &T) -> bool { return (*self) <= (*other); }
fn le(&self, other: &T) -> bool { return (*self) <= (*other); }
#[inline(always)]
pure fn ge(&self, other: &T) -> bool { return (*self) >= (*other); }
fn ge(&self, other: &T) -> bool { return (*self) >= (*other); }
#[inline(always)]
pure fn gt(&self, other: &T) -> bool { return (*self) > (*other); }
fn gt(&self, other: &T) -> bool { return (*self) > (*other); }
}
#[cfg(notest)]
impl Eq for T {
#[inline(always)]
pure fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
#[inline(always)]
pure fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
}
impl num::Zero for T {
#[inline(always)]
pure fn zero() -> T { 0 }
fn zero() -> T { 0 }
}
impl num::One for T {
#[inline(always)]
pure fn one() -> T { 1 }
fn one() -> T { 1 }
}
#[cfg(notest)]
impl ops::Add<T,T> for T {
pure fn add(&self, other: &T) -> T { *self + *other }
fn add(&self, other: &T) -> T { *self + *other }
}
#[cfg(notest)]
impl ops::Sub<T,T> for T {
pure fn sub(&self, other: &T) -> T { *self - *other }
fn sub(&self, other: &T) -> T { *self - *other }
}
#[cfg(notest)]
impl ops::Mul<T,T> for T {
pure fn mul(&self, other: &T) -> T { *self * *other }
fn mul(&self, other: &T) -> T { *self * *other }
}
#[cfg(notest)]
impl ops::Div<T,T> for T {
pure fn div(&self, other: &T) -> T { *self / *other }
fn div(&self, other: &T) -> T { *self / *other }
}
#[cfg(notest)]
impl ops::Modulo<T,T> for T {
pure fn modulo(&self, other: &T) -> T { *self % *other }
fn modulo(&self, other: &T) -> T { *self % *other }
}
#[cfg(notest)]
impl ops::Neg<T> for T {
pure fn neg(&self) -> T { -*self }
fn neg(&self) -> T { -*self }
}
// String conversion functions and impl str -> num
/// Parse a string as a number in base 10.
#[inline(always)]
pub pure fn from_str(s: &str) -> Option<T> {
pub fn from_str(s: &str) -> Option<T> {
strconv::from_str_common(s, 10u, true, false, false,
strconv::ExpNone, false)
}
/// Parse a string as a number in the given base.
#[inline(always)]
pub pure fn from_str_radix(s: &str, radix: uint) -> Option<T> {
pub fn from_str_radix(s: &str, radix: uint) -> Option<T> {
strconv::from_str_common(s, radix, true, false, false,
strconv::ExpNone, false)
}
/// Parse a byte slice as a number in the given base.
#[inline(always)]
pub pure fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
strconv::from_str_bytes_common(buf, radix, true, false, false,
strconv::ExpNone, false)
}
impl FromStr for T {
#[inline(always)]
pure fn from_str(s: &str) -> Option<T> {
fn from_str(s: &str) -> Option<T> {
from_str(s)
}
}
impl FromStrRadix for T {
#[inline(always)]
pure fn from_str_radix(s: &str, radix: uint) -> Option<T> {
fn from_str_radix(s: &str, radix: uint) -> Option<T> {
from_str_radix(s, radix)
}
}
@@ -237,7 +237,7 @@ impl FromStrRadix for T {
/// Convert to a string as a byte slice in a given base.
#[inline(always)]
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
pub fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
strconv::SignNeg, strconv::DigAll);
f(buf)
@@ -245,7 +245,7 @@ impl FromStrRadix for T {
/// Convert to a string in base 10.
#[inline(always)]
pub pure fn to_str(num: T) -> ~str {
pub fn to_str(num: T) -> ~str {
let (buf, _) = strconv::to_str_common(&num, 10u, false,
strconv::SignNeg, strconv::DigAll);
buf
@@ -253,7 +253,7 @@ impl FromStrRadix for T {
/// Convert to a string in a given base.
#[inline(always)]
pub pure fn to_str_radix(num: T, radix: uint) -> ~str {
pub fn to_str_radix(num: T, radix: uint) -> ~str {
let (buf, _) = strconv::to_str_common(&num, radix, false,
strconv::SignNeg, strconv::DigAll);
buf
@@ -261,14 +261,14 @@ impl FromStrRadix for T {
impl ToStr for T {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
to_str(*self)
}
}
impl ToStrRadix for T {
#[inline(always)]
pure fn to_str_radix(&self, radix: uint) -> ~str {
fn to_str_radix(&self, radix: uint) -> ~str {
to_str_radix(*self, radix)
}
}
+14 -14
View File
@@ -22,23 +22,23 @@ impl NumCast for i16 {
* Cast `n` to a `i16`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> i16 { n.to_i16() }
fn from<N:NumCast>(n: N) -> i16 { n.to_i16() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+14 -14
View File
@@ -22,23 +22,23 @@ impl NumCast for i32 {
* Cast `n` to a `i32`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> i32 { n.to_i32() }
fn from<N:NumCast>(n: N) -> i32 { n.to_i32() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+14 -14
View File
@@ -22,23 +22,23 @@ impl NumCast for i64 {
* Cast `n` to a `i64`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> i64 { n.to_i64() }
fn from<N:NumCast>(n: N) -> i64 { n.to_i64() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+14 -14
View File
@@ -22,23 +22,23 @@ impl NumCast for i8 {
* Cast `n` to a `i8`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> i8 { n.to_i8() }
fn from<N:NumCast>(n: N) -> i8 { n.to_i8() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+15 -15
View File
@@ -19,7 +19,7 @@ mod inst {
pub const bits: uint = ::uint::bits;
/// Returns `base` raised to the power of `exponent`
pub pure fn pow(base: int, exponent: uint) -> int {
pub fn pow(base: int, exponent: uint) -> int {
if exponent == 0u {
//Not mathemtically true if ~[base == 0]
return 1;
@@ -63,23 +63,23 @@ impl NumCast for int {
* Cast `n` to a `int`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> int { n.to_int() }
fn from<N:NumCast>(n: N) -> int { n.to_int() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+27 -27
View File
@@ -17,28 +17,28 @@
pub mod strconv;
pub trait IntConvertible {
pure fn to_int(&self) -> int;
pure fn from_int(n: int) -> Self;
fn to_int(&self) -> int;
fn from_int(n: int) -> Self;
}
pub trait Zero {
pure fn zero() -> Self;
fn zero() -> Self;
}
pub trait One {
pure fn one() -> Self;
fn one() -> Self;
}
pub pure fn abs<T:Ord + Zero + Neg<T>>(v: T) -> T {
pub fn abs<T:Ord + Zero + Neg<T>>(v: T) -> T {
if v < Zero::zero() { v.neg() } else { v }
}
pub trait Round {
pure fn round(&self, mode: RoundMode) -> Self;
fn round(&self, mode: RoundMode) -> Self;
pure fn floor(&self) -> Self;
pure fn ceil(&self) -> Self;
pure fn fract(&self) -> Self;
fn floor(&self) -> Self;
fn ceil(&self) -> Self;
fn fract(&self) -> Self;
}
pub enum RoundMode {
@@ -59,7 +59,7 @@ pub enum RoundMode {
* ~~~
*/
#[inline(always)]
pub pure fn cast<T:NumCast,U:NumCast>(n: T) -> U {
pub fn cast<T:NumCast,U:NumCast>(n: T) -> U {
NumCast::from(n)
}
@@ -67,31 +67,31 @@ pub enum RoundMode {
* An interface for generic numeric type casts
*/
pub trait NumCast {
pure fn from<T:NumCast>(n: T) -> Self;
fn from<T:NumCast>(n: T) -> Self;
pure fn to_u8(&self) -> u8;
pure fn to_u16(&self) -> u16;
pure fn to_u32(&self) -> u32;
pure fn to_u64(&self) -> u64;
pure fn to_uint(&self) -> uint;
fn to_u8(&self) -> u8;
fn to_u16(&self) -> u16;
fn to_u32(&self) -> u32;
fn to_u64(&self) -> u64;
fn to_uint(&self) -> uint;
pure fn to_i8(&self) -> i8;
pure fn to_i16(&self) -> i16;
pure fn to_i32(&self) -> i32;
pure fn to_i64(&self) -> i64;
pure fn to_int(&self) -> int;
fn to_i8(&self) -> i8;
fn to_i16(&self) -> i16;
fn to_i32(&self) -> i32;
fn to_i64(&self) -> i64;
fn to_int(&self) -> int;
pure fn to_f32(&self) -> f32;
pure fn to_f64(&self) -> f64;
pure fn to_float(&self) -> float;
fn to_f32(&self) -> f32;
fn to_f64(&self) -> f64;
fn to_float(&self) -> float;
}
pub trait ToStrRadix {
pub pure fn to_str_radix(&self, radix: uint) -> ~str;
pub fn to_str_radix(&self, radix: uint) -> ~str;
}
pub trait FromStrRadix {
pub pure fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
pub fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
}
// Generic math functions:
@@ -109,7 +109,7 @@ pub trait FromStrRadix {
* - If code written to use this function doesn't care about it, it's
* probably assuming that `x^0` always equals `1`.
*/
pub pure fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
radix: uint, pow: uint) -> T {
let _0: T = Zero::zero();
let _1: T = One::one();
+26 -26
View File
@@ -37,12 +37,12 @@ pub enum SignFormat {
}
#[inline(always)]
pure fn is_NaN<T:Eq>(num: &T) -> bool {
fn is_NaN<T:Eq>(num: &T) -> bool {
*num != *num
}
#[inline(always)]
pure fn is_inf<T:Eq+NumStrConv>(num: &T) -> bool {
fn is_inf<T:Eq+NumStrConv>(num: &T) -> bool {
match NumStrConv::inf() {
None => false,
Some(n) => *num == n
@@ -50,7 +50,7 @@ pub enum SignFormat {
}
#[inline(always)]
pure fn is_neg_inf<T:Eq+NumStrConv>(num: &T) -> bool {
fn is_neg_inf<T:Eq+NumStrConv>(num: &T) -> bool {
match NumStrConv::neg_inf() {
None => false,
Some(n) => *num == n
@@ -58,7 +58,7 @@ pub enum SignFormat {
}
#[inline(always)]
pure fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Div<T,T>>(num: &T) -> bool {
fn is_neg_zero<T:Eq+One+Zero+NumStrConv+Div<T,T>>(num: &T) -> bool {
let _0: T = Zero::zero();
let _1: T = One::one();
@@ -66,35 +66,35 @@ pub enum SignFormat {
}
pub trait NumStrConv {
pure fn NaN() -> Option<Self>;
pure fn inf() -> Option<Self>;
pure fn neg_inf() -> Option<Self>;
pure fn neg_zero() -> Option<Self>;
fn NaN() -> Option<Self>;
fn inf() -> Option<Self>;
fn neg_inf() -> Option<Self>;
fn neg_zero() -> Option<Self>;
pure fn round_to_zero(&self) -> Self;
pure fn fractional_part(&self) -> Self;
fn round_to_zero(&self) -> Self;
fn fractional_part(&self) -> Self;
}
macro_rules! impl_NumStrConv_Floating (($t:ty) => (
impl NumStrConv for $t {
#[inline(always)]
pure fn NaN() -> Option<$t> { Some( 0.0 / 0.0) }
fn NaN() -> Option<$t> { Some( 0.0 / 0.0) }
#[inline(always)]
pure fn inf() -> Option<$t> { Some( 1.0 / 0.0) }
fn inf() -> Option<$t> { Some( 1.0 / 0.0) }
#[inline(always)]
pure fn neg_inf() -> Option<$t> { Some(-1.0 / 0.0) }
fn neg_inf() -> Option<$t> { Some(-1.0 / 0.0) }
#[inline(always)]
pure fn neg_zero() -> Option<$t> { Some(-0.0 ) }
fn neg_zero() -> Option<$t> { Some(-0.0 ) }
#[inline(always)]
pure fn round_to_zero(&self) -> $t {
fn round_to_zero(&self) -> $t {
( if *self < 0.0 { f64::ceil(*self as f64) }
else { f64::floor(*self as f64) }
) as $t
}
#[inline(always)]
pure fn fractional_part(&self) -> $t {
fn fractional_part(&self) -> $t {
*self - self.round_to_zero()
}
}
@@ -102,13 +102,13 @@ impl NumStrConv for $t {
macro_rules! impl_NumStrConv_Integer (($t:ty) => (
impl NumStrConv for $t {
#[inline(always)] pure fn NaN() -> Option<$t> { None }
#[inline(always)] pure fn inf() -> Option<$t> { None }
#[inline(always)] pure fn neg_inf() -> Option<$t> { None }
#[inline(always)] pure fn neg_zero() -> Option<$t> { None }
#[inline(always)] fn NaN() -> Option<$t> { None }
#[inline(always)] fn inf() -> Option<$t> { None }
#[inline(always)] fn neg_inf() -> Option<$t> { None }
#[inline(always)] fn neg_zero() -> Option<$t> { None }
#[inline(always)] pure fn round_to_zero(&self) -> $t { *self }
#[inline(always)] pure fn fractional_part(&self) -> $t { 0 }
#[inline(always)] fn round_to_zero(&self) -> $t { *self }
#[inline(always)] fn fractional_part(&self) -> $t { 0 }
}
))
@@ -161,7 +161,7 @@ impl NumStrConv for $t {
* # Failure
* - Fails if `radix` < 2 or `radix` > 36.
*/
pub pure fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
pub fn to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
Div<T,T>+Neg<T>+Modulo<T,T>+Mul<T,T>>(
num: &T, radix: uint, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits) -> (~[u8], bool) {
@@ -383,7 +383,7 @@ impl NumStrConv for $t {
* `to_str_bytes_common()`, for details see there.
*/
#[inline(always)]
pub pure fn to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
pub fn to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Copy+
Div<T,T>+Neg<T>+Modulo<T,T>+Mul<T,T>>(
num: &T, radix: uint, negative_zero: bool,
sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
@@ -439,7 +439,7 @@ impl NumStrConv for $t {
* - Could accept option to allow ignoring underscores, allowing for numbers
* formated like `FF_AE_FF_FF`.
*/
pub pure fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
pub fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+
NumStrConv>(
buf: &[u8], radix: uint, negative: bool, fractional: bool,
@@ -628,7 +628,7 @@ impl NumStrConv for $t {
* `from_str_bytes_common()`, for details see there.
*/
#[inline(always)]
pub pure fn from_str_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+Mul<T,T>+
pub fn from_str_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+Mul<T,T>+
Sub<T,T>+Neg<T>+Add<T,T>+NumStrConv>(
buf: &str, radix: uint, negative: bool, fractional: bool,
special: bool, exponent: ExponentFormat, empty_zero: bool
+43 -43
View File
@@ -30,44 +30,44 @@
pub const max_value: T = 0 as T - 1 as T;
#[inline(always)]
pub pure fn add(x: T, y: T) -> T { x + y }
pub fn add(x: T, y: T) -> T { x + y }
#[inline(always)]
pub pure fn sub(x: T, y: T) -> T { x - y }
pub fn sub(x: T, y: T) -> T { x - y }
#[inline(always)]
pub pure fn mul(x: T, y: T) -> T { x * y }
pub fn mul(x: T, y: T) -> T { x * y }
#[inline(always)]
pub pure fn div(x: T, y: T) -> T { x / y }
pub fn div(x: T, y: T) -> T { x / y }
#[inline(always)]
pub pure fn rem(x: T, y: T) -> T { x % y }
pub fn rem(x: T, y: T) -> T { x % y }
#[inline(always)]
pub pure fn lt(x: T, y: T) -> bool { x < y }
pub fn lt(x: T, y: T) -> bool { x < y }
#[inline(always)]
pub pure fn le(x: T, y: T) -> bool { x <= y }
pub fn le(x: T, y: T) -> bool { x <= y }
#[inline(always)]
pub pure fn eq(x: T, y: T) -> bool { x == y }
pub fn eq(x: T, y: T) -> bool { x == y }
#[inline(always)]
pub pure fn ne(x: T, y: T) -> bool { x != y }
pub fn ne(x: T, y: T) -> bool { x != y }
#[inline(always)]
pub pure fn ge(x: T, y: T) -> bool { x >= y }
pub fn ge(x: T, y: T) -> bool { x >= y }
#[inline(always)]
pub pure fn gt(x: T, y: T) -> bool { x > y }
pub fn gt(x: T, y: T) -> bool { x > y }
#[inline(always)]
pub pure fn is_positive(x: T) -> bool { x > 0 as T }
pub fn is_positive(x: T) -> bool { x > 0 as T }
#[inline(always)]
pub pure fn is_negative(x: T) -> bool { x < 0 as T }
pub fn is_negative(x: T) -> bool { x < 0 as T }
#[inline(always)]
pub pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
pub fn is_nonpositive(x: T) -> bool { x <= 0 as T }
#[inline(always)]
pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
pub fn is_nonnegative(x: T) -> bool { x >= 0 as T }
#[inline(always)]
/**
* Iterate over the range [`start`,`start`+`step`..`stop`)
*
*/
pub pure fn range_step(start: T,
pub fn range_step(start: T,
stop: T,
step: T_SIGNED,
it: &fn(T) -> bool) {
@@ -91,110 +91,110 @@
#[inline(always)]
/// Iterate over the range [`lo`..`hi`)
pub pure fn range(lo: T, hi: T, it: &fn(T) -> bool) {
pub fn range(lo: T, hi: T, it: &fn(T) -> bool) {
range_step(lo, hi, 1 as T_SIGNED, it);
}
#[inline(always)]
/// Iterate over the range [`hi`..`lo`)
pub pure fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
pub fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
range_step(hi, lo, -1 as T_SIGNED, it);
}
/// Computes the bitwise complement
#[inline(always)]
pub pure fn compl(i: T) -> T {
pub fn compl(i: T) -> T {
max_value ^ i
}
#[cfg(notest)]
impl Ord for T {
#[inline(always)]
pure fn lt(&self, other: &T) -> bool { (*self) < (*other) }
fn lt(&self, other: &T) -> bool { (*self) < (*other) }
#[inline(always)]
pure fn le(&self, other: &T) -> bool { (*self) <= (*other) }
fn le(&self, other: &T) -> bool { (*self) <= (*other) }
#[inline(always)]
pure fn ge(&self, other: &T) -> bool { (*self) >= (*other) }
fn ge(&self, other: &T) -> bool { (*self) >= (*other) }
#[inline(always)]
pure fn gt(&self, other: &T) -> bool { (*self) > (*other) }
fn gt(&self, other: &T) -> bool { (*self) > (*other) }
}
#[cfg(notest)]
impl Eq for T {
#[inline(always)]
pure fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
#[inline(always)]
pure fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
}
impl num::Zero for T {
#[inline(always)]
pure fn zero() -> T { 0 }
fn zero() -> T { 0 }
}
impl num::One for T {
#[inline(always)]
pure fn one() -> T { 1 }
fn one() -> T { 1 }
}
#[cfg(notest)]
impl ops::Add<T,T> for T {
pure fn add(&self, other: &T) -> T { *self + *other }
fn add(&self, other: &T) -> T { *self + *other }
}
#[cfg(notest)]
impl ops::Sub<T,T> for T {
pure fn sub(&self, other: &T) -> T { *self - *other }
fn sub(&self, other: &T) -> T { *self - *other }
}
#[cfg(notest)]
impl ops::Mul<T,T> for T {
pure fn mul(&self, other: &T) -> T { *self * *other }
fn mul(&self, other: &T) -> T { *self * *other }
}
#[cfg(notest)]
impl ops::Div<T,T> for T {
pure fn div(&self, other: &T) -> T { *self / *other }
fn div(&self, other: &T) -> T { *self / *other }
}
#[cfg(notest)]
impl ops::Modulo<T,T> for T {
pure fn modulo(&self, other: &T) -> T { *self % *other }
fn modulo(&self, other: &T) -> T { *self % *other }
}
#[cfg(notest)]
impl ops::Neg<T> for T {
pure fn neg(&self) -> T { -*self }
fn neg(&self) -> T { -*self }
}
// String conversion functions and impl str -> num
/// Parse a string as a number in base 10.
#[inline(always)]
pub pure fn from_str(s: &str) -> Option<T> {
pub fn from_str(s: &str) -> Option<T> {
strconv::from_str_common(s, 10u, false, false, false,
strconv::ExpNone, false)
}
/// Parse a string as a number in the given base.
#[inline(always)]
pub pure fn from_str_radix(s: &str, radix: uint) -> Option<T> {
pub fn from_str_radix(s: &str, radix: uint) -> Option<T> {
strconv::from_str_common(s, radix, false, false, false,
strconv::ExpNone, false)
}
/// Parse a byte slice as a number in the given base.
#[inline(always)]
pub pure fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
strconv::from_str_bytes_common(buf, radix, false, false, false,
strconv::ExpNone, false)
}
impl FromStr for T {
#[inline(always)]
pure fn from_str(s: &str) -> Option<T> {
fn from_str(s: &str) -> Option<T> {
from_str(s)
}
}
impl FromStrRadix for T {
#[inline(always)]
pure fn from_str_radix(s: &str, radix: uint) -> Option<T> {
fn from_str_radix(s: &str, radix: uint) -> Option<T> {
from_str_radix(s, radix)
}
}
@@ -203,7 +203,7 @@ impl FromStrRadix for T {
/// Convert to a string as a byte slice in a given base.
#[inline(always)]
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
pub fn to_str_bytes<U>(n: T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
strconv::SignNeg, strconv::DigAll);
f(buf)
@@ -211,7 +211,7 @@ impl FromStrRadix for T {
/// Convert to a string in base 10.
#[inline(always)]
pub pure fn to_str(num: T) -> ~str {
pub fn to_str(num: T) -> ~str {
let (buf, _) = strconv::to_str_common(&num, 10u, false,
strconv::SignNeg, strconv::DigAll);
buf
@@ -219,7 +219,7 @@ impl FromStrRadix for T {
/// Convert to a string in a given base.
#[inline(always)]
pub pure fn to_str_radix(num: T, radix: uint) -> ~str {
pub fn to_str_radix(num: T, radix: uint) -> ~str {
let (buf, _) = strconv::to_str_common(&num, radix, false,
strconv::SignNeg, strconv::DigAll);
buf
@@ -227,14 +227,14 @@ impl FromStrRadix for T {
impl ToStr for T {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
to_str(*self)
}
}
impl ToStrRadix for T {
#[inline(always)]
pure fn to_str_radix(&self, radix: uint) -> ~str {
fn to_str_radix(&self, radix: uint) -> ~str {
to_str_radix(*self, radix)
}
}
+14 -14
View File
@@ -24,23 +24,23 @@ impl NumCast for u16 {
* Cast `n` to a `u16`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> u16 { n.to_u16() }
fn from<N:NumCast>(n: N) -> u16 { n.to_u16() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+14 -14
View File
@@ -24,23 +24,23 @@ impl NumCast for u32 {
* Cast `n` to a `u32`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> u32 { n.to_u32() }
fn from<N:NumCast>(n: N) -> u32 { n.to_u32() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+14 -14
View File
@@ -24,23 +24,23 @@ impl NumCast for u64 {
* Cast `n` to a `u64`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> u64 { n.to_u64() }
fn from<N:NumCast>(n: N) -> u64 { n.to_u64() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+15 -15
View File
@@ -23,7 +23,7 @@ mod inst {
// Type-specific functions here. These must be reexported by the
// parent module so that they appear in core::u8 and not core::u8::u8;
pub pure fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; }
pub fn is_ascii(x: T) -> bool { return 0 as T == x & 128 as T; }
}
impl NumCast for u8 {
@@ -31,23 +31,23 @@ impl NumCast for u8 {
* Cast `n` to a `u8`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> u8 { n.to_u8() }
fn from<N:NumCast>(n: N) -> u8 { n.to_u8() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] fn to_u8(&self) -> u8 { *self }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self as uint }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+20 -20
View File
@@ -45,7 +45,7 @@ pub mod inst {
*
* The smallest integer `q` such that `x/y <= q`.
*/
pub pure fn div_ceil(x: uint, y: uint) -> uint {
pub fn div_ceil(x: uint, y: uint) -> uint {
let div = x / y;
if x % y == 0u { div }
else { div + 1u }
@@ -63,7 +63,7 @@ pub mod inst {
*
* The integer `q` closest to `x/y`.
*/
pub pure fn div_round(x: uint, y: uint) -> uint {
pub fn div_round(x: uint, y: uint) -> uint {
let div = x / y;
if x % y * 2u < y { div }
else { div + 1u }
@@ -84,7 +84,7 @@ pub mod inst {
* The smallest integer `q` such that `x/y <= q`. This
* is either `x/y` or `x/y + 1`.
*/
pub pure fn div_floor(x: uint, y: uint) -> uint { return x / y; }
pub fn div_floor(x: uint, y: uint) -> uint { return x / y; }
/**
* Iterate over the range [`lo`..`hi`), or stop when requested
@@ -101,7 +101,7 @@ pub mod inst {
* `true` If execution proceeded correctly, `false` if it was interrupted,
* that is if `it` returned `false` at any point.
*/
pub pure fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
pub fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
let mut i = lo;
while i < hi {
if (!it(i)) { return false; }
@@ -122,7 +122,7 @@ impl iter::Times for uint {
* use with integer literals of inferred integer-type as
* the self-value (eg. `for 100.times { ... }`).
*/
pure fn times(&self, it: &fn() -> bool) {
fn times(&self, it: &fn() -> bool) {
let mut i = *self;
while i > 0 {
if !it() { break }
@@ -133,7 +133,7 @@ impl iter::Times for uint {
/// Returns the smallest power of 2 greater than or equal to `n`
#[inline(always)]
pub pure fn next_power_of_two(n: uint) -> uint {
pub fn next_power_of_two(n: uint) -> uint {
let halfbits: uint = sys::size_of::<uint>() * 4u;
let mut tmp: uint = n - 1u;
let mut shift: uint = 1u;
@@ -215,23 +215,23 @@ impl NumCast for uint {
* Cast `n` to a `uint`
*/
#[inline(always)]
pure fn from<N:NumCast>(n: N) -> uint { n.to_uint() }
fn from<N:NumCast>(n: N) -> uint { n.to_uint() }
#[inline(always)] pure fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] pure fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] pure fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] pure fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] pure fn to_uint(&self) -> uint { *self }
#[inline(always)] fn to_u8(&self) -> u8 { *self as u8 }
#[inline(always)] fn to_u16(&self) -> u16 { *self as u16 }
#[inline(always)] fn to_u32(&self) -> u32 { *self as u32 }
#[inline(always)] fn to_u64(&self) -> u64 { *self as u64 }
#[inline(always)] fn to_uint(&self) -> uint { *self }
#[inline(always)] pure fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] pure fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] pure fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] pure fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] pure fn to_int(&self) -> int { *self as int }
#[inline(always)] fn to_i8(&self) -> i8 { *self as i8 }
#[inline(always)] fn to_i16(&self) -> i16 { *self as i16 }
#[inline(always)] fn to_i32(&self) -> i32 { *self as i32 }
#[inline(always)] fn to_i64(&self) -> i64 { *self as i64 }
#[inline(always)] fn to_int(&self) -> int { *self as int }
#[inline(always)] pure fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] pure fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] pure fn to_float(&self) -> float { *self as float }
#[inline(always)] fn to_f32(&self) -> f32 { *self as f32 }
#[inline(always)] fn to_f64(&self) -> f64 { *self as f64 }
#[inline(always)] fn to_float(&self) -> float { *self as float }
}
#[test]
+13 -13
View File
@@ -17,65 +17,65 @@ pub trait Drop {
#[lang="add"]
pub trait Add<RHS,Result> {
pure fn add(&self, rhs: &RHS) -> Result;
fn add(&self, rhs: &RHS) -> Result;
}
#[lang="sub"]
pub trait Sub<RHS,Result> {
pure fn sub(&self, rhs: &RHS) -> Result;
fn sub(&self, rhs: &RHS) -> Result;
}
#[lang="mul"]
pub trait Mul<RHS,Result> {
pure fn mul(&self, rhs: &RHS) -> Result;
fn mul(&self, rhs: &RHS) -> Result;
}
#[lang="div"]
pub trait Div<RHS,Result> {
pure fn div(&self, rhs: &RHS) -> Result;
fn div(&self, rhs: &RHS) -> Result;
}
#[lang="modulo"]
pub trait Modulo<RHS,Result> {
pure fn modulo(&self, rhs: &RHS) -> Result;
fn modulo(&self, rhs: &RHS) -> Result;
}
#[lang="neg"]
pub trait Neg<Result> {
pure fn neg(&self) -> Result;
fn neg(&self) -> Result;
}
#[lang="not"]
pub trait Not<Result> {
pure fn not(&self) -> Result;
fn not(&self) -> Result;
}
#[lang="bitand"]
pub trait BitAnd<RHS,Result> {
pure fn bitand(&self, rhs: &RHS) -> Result;
fn bitand(&self, rhs: &RHS) -> Result;
}
#[lang="bitor"]
pub trait BitOr<RHS,Result> {
pure fn bitor(&self, rhs: &RHS) -> Result;
fn bitor(&self, rhs: &RHS) -> Result;
}
#[lang="bitxor"]
pub trait BitXor<RHS,Result> {
pure fn bitxor(&self, rhs: &RHS) -> Result;
fn bitxor(&self, rhs: &RHS) -> Result;
}
#[lang="shl"]
pub trait Shl<RHS,Result> {
pure fn shl(&self, rhs: &RHS) -> Result;
fn shl(&self, rhs: &RHS) -> Result;
}
#[lang="shr"]
pub trait Shr<RHS,Result> {
pure fn shr(&self, rhs: &RHS) -> Result;
fn shr(&self, rhs: &RHS) -> Result;
}
#[lang="index"]
pub trait Index<Index,Result> {
pure fn index(&self, index: Index) -> Result;
fn index(&self, index: Index) -> Result;
}
+38 -38
View File
@@ -59,7 +59,7 @@ pub enum Option<T> {
}
impl<T:Ord> Ord for Option<T> {
pure fn lt(&self, other: &Option<T>) -> bool {
fn lt(&self, other: &Option<T>) -> bool {
match (self, other) {
(&None, &None) => false,
(&None, &Some(_)) => true,
@@ -68,7 +68,7 @@ impl<T:Ord> Ord for Option<T> {
}
}
pure fn le(&self, other: &Option<T>) -> bool {
fn le(&self, other: &Option<T>) -> bool {
match (self, other) {
(&None, &None) => true,
(&None, &Some(_)) => true,
@@ -77,18 +77,18 @@ impl<T:Ord> Ord for Option<T> {
}
}
pure fn ge(&self, other: &Option<T>) -> bool {
fn ge(&self, other: &Option<T>) -> bool {
! (self < other)
}
pure fn gt(&self, other: &Option<T>) -> bool {
fn gt(&self, other: &Option<T>) -> bool {
! (self <= other)
}
}
impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
#[inline(always)]
pure fn add(&self, other: &Option<T>) -> Option<T> {
fn add(&self, other: &Option<T>) -> Option<T> {
match (*self, *other) {
(None, None) => None,
(_, None) => *self,
@@ -99,7 +99,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn get<T:Copy>(opt: Option<T>) -> T {
pub fn get<T:Copy>(opt: Option<T>) -> T {
/*!
Gets the value out of an option
@@ -122,7 +122,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
pub fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
/*!
Gets an immutable reference to the value inside an option.
@@ -143,7 +143,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
}
pub pure fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
pub fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
/*!
Gets a mutable reference to the value inside an option.
@@ -165,14 +165,14 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn map<T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> {
pub fn map<T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> {
//! Maps a `some` value by reference from one type to another
match *opt { Some(ref x) => Some(f(x)), None => None }
}
#[inline(always)]
pub pure fn map_consume<T, U>(opt: Option<T>,
pub fn map_consume<T, U>(opt: Option<T>,
f: &fn(v: T) -> U) -> Option<U> {
/*!
* As `map`, but consumes the option and gives `f` ownership to avoid
@@ -182,7 +182,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn chain<T, U>(opt: Option<T>,
pub fn chain<T, U>(opt: Option<T>,
f: &fn(t: T) -> Option<U>) -> Option<U> {
/*!
* Update an optional value by optionally running its content through a
@@ -196,7 +196,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn chain_ref<T, U>(opt: &Option<T>,
pub fn chain_ref<T, U>(opt: &Option<T>,
f: &fn(x: &T) -> Option<U>) -> Option<U> {
/*!
* Update an optional value by optionally running its content by reference
@@ -207,7 +207,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
pub fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
/*!
* Returns the leftmost Some() value, or None if both are None.
*/
@@ -218,7 +218,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) {
pub fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) {
//! Applies a function zero or more times until the result is none.
let mut opt = x;
@@ -228,35 +228,35 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn is_none<T>(opt: &const Option<T>) -> bool {
pub fn is_none<T>(opt: &const Option<T>) -> bool {
//! Returns true if the option equals `none`
match *opt { None => true, Some(_) => false }
}
#[inline(always)]
pub pure fn is_some<T>(opt: &const Option<T>) -> bool {
pub fn is_some<T>(opt: &const Option<T>) -> bool {
//! Returns true if the option contains some value
!is_none(opt)
}
#[inline(always)]
pub pure fn get_or_zero<T:Copy + Zero>(opt: Option<T>) -> T {
pub fn get_or_zero<T:Copy + Zero>(opt: Option<T>) -> T {
//! Returns the contained value or zero (for this type)
match opt { Some(copy x) => x, None => Zero::zero() }
}
#[inline(always)]
pub pure fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T {
pub fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T {
//! Returns the contained value or a default
match opt { Some(copy x) => x, None => def }
}
#[inline(always)]
pub pure fn map_default<T, U>(opt: &'r Option<T>, def: U,
pub fn map_default<T, U>(opt: &'r Option<T>, def: U,
f: &fn(&'r T) -> U) -> U {
//! Applies a function to the contained value or returns a default
@@ -264,7 +264,7 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
}
#[inline(always)]
pub pure fn unwrap<T>(opt: Option<T>) -> T {
pub fn unwrap<T>(opt: Option<T>) -> T {
/*!
Moves a value out of an option type and returns it.
@@ -302,7 +302,7 @@ pub fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
}
#[inline(always)]
pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
pub fn expect<T>(opt: Option<T>, reason: &str) -> T {
//! As unwrap, but with a specified failure message.
match opt {
Some(val) => val,
@@ -313,12 +313,12 @@ pub fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
impl<T> BaseIter<T> for Option<T> {
/// Performs an operation on the contained value by reference
#[inline(always)]
pure fn each(&self, f: &fn(x: &'self T) -> bool) {
fn each(&self, f: &fn(x: &'self T) -> bool) {
match *self { None => (), Some(ref t) => { f(t); } }
}
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> {
fn size_hint(&self) -> Option<uint> {
if self.is_some() { Some(1) } else { Some(0) }
}
}
@@ -333,42 +333,42 @@ fn each_mut(&mut self, f: &fn(&'self mut T) -> bool) {
pub impl<T> Option<T> {
/// Returns true if the option equals `none`
#[inline(always)]
pure fn is_none(&const self) -> bool { is_none(self) }
fn is_none(&const self) -> bool { is_none(self) }
/// Returns true if the option contains some value
#[inline(always)]
pure fn is_some(&const self) -> bool { is_some(self) }
fn is_some(&const self) -> bool { is_some(self) }
/**
* Update an optional value by optionally running its content by reference
* through a function that returns an option.
*/
#[inline(always)]
pure fn chain_ref<U>(&self, f: &fn(x: &T) -> Option<U>) -> Option<U> {
fn chain_ref<U>(&self, f: &fn(x: &T) -> Option<U>) -> Option<U> {
chain_ref(self, f)
}
/// Maps a `some` value from one type to another by reference
#[inline(always)]
pure fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> { map(self, f) }
fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> { map(self, f) }
/// As `map`, but consumes the option and gives `f` ownership to avoid
/// copying.
#[inline(always)]
pure fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
map_consume(self, f)
}
/// Applies a function to the contained value or returns a default
#[inline(always)]
pure fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U {
fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U {
map_default(self, def, f)
}
/// As `map_default`, but consumes the option and gives `f`
/// ownership to avoid copying.
#[inline(always)]
pure fn map_consume_default<U>(self, def: U, f: &fn(v: T) -> U) -> U {
fn map_consume_default<U>(self, def: U, f: &fn(v: T) -> U) -> U {
match self { None => def, Some(v) => f(v) }
}
@@ -403,7 +403,7 @@ fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
case explicitly.
*/
#[inline(always)]
pure fn get_ref(&self) -> &'self T { get_ref(self) }
fn get_ref(&self) -> &'self T { get_ref(self) }
/**
Gets a mutable reference to the value inside an option.
@@ -420,7 +420,7 @@ fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
case explicitly.
*/
#[inline(always)]
pure fn get_mut_ref(&mut self) -> &'self mut T { get_mut_ref(self) }
fn get_mut_ref(&mut self) -> &'self mut T { get_mut_ref(self) }
/**
* Gets the value out of an option without copying.
@@ -430,7 +430,7 @@ fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
* Fails if the value equals `none`
*/
#[inline(always)]
pure fn unwrap(self) -> T { unwrap(self) }
fn unwrap(self) -> T { unwrap(self) }
/**
* The option dance. Moves a value out of an option type and returns it,
@@ -452,7 +452,7 @@ fn swap_unwrap(&mut self) -> T { swap_unwrap(self) }
* Fails if the value equals `none`
*/
#[inline(always)]
pure fn expect(self, reason: &str) -> T { expect(self, reason) }
fn expect(self, reason: &str) -> T { expect(self, reason) }
}
pub impl<T:Copy> Option<T> {
@@ -471,21 +471,21 @@ pub impl<T:Copy> Option<T> {
case explicitly.
*/
#[inline(always)]
pure fn get(self) -> T { get(self) }
fn get(self) -> T { get(self) }
#[inline(always)]
pure fn get_or_default(self, def: T) -> T { get_or_default(self, def) }
fn get_or_default(self, def: T) -> T { get_or_default(self, def) }
/// Applies a function zero or more times until the result is none.
#[inline(always)]
pure fn while_some(self, blk: &fn(v: T) -> Option<T>) {
fn while_some(self, blk: &fn(v: T) -> Option<T>) {
while_some(self, blk)
}
}
pub impl<T:Copy + Zero> Option<T> {
#[inline(always)]
pure fn get_or_zero(self) -> T { get_or_zero(self) }
fn get_or_zero(self) -> T { get_or_zero(self) }
}
#[test]
+6 -6
View File
@@ -15,20 +15,20 @@
#[cfg(notest)]
impl<T:Eq> Eq for ~T {
#[inline(always)]
pure fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) }
fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) }
#[inline(always)]
pure fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) }
fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) }
}
#[cfg(notest)]
impl<T:Ord> Ord for ~T {
#[inline(always)]
pure fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) }
fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) }
#[inline(always)]
pure fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) }
fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) }
#[inline(always)]
pure fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) }
fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) }
#[inline(always)]
pure fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
}
+64 -64
View File
@@ -28,7 +28,7 @@ pub struct WindowsPath {
components: ~[~str],
}
pub pure fn WindowsPath(s: &str) -> WindowsPath {
pub fn WindowsPath(s: &str) -> WindowsPath {
GenericPath::from_str(s)
}
@@ -38,42 +38,42 @@ pub struct PosixPath {
components: ~[~str],
}
pub pure fn PosixPath(s: &str) -> PosixPath {
pub fn PosixPath(s: &str) -> PosixPath {
GenericPath::from_str(s)
}
pub trait GenericPath {
pure fn from_str(&str) -> Self;
fn from_str(&str) -> Self;
pure fn dirname(&self) -> ~str;
pure fn filename(&self) -> Option<~str>;
pure fn filestem(&self) -> Option<~str>;
pure fn filetype(&self) -> Option<~str>;
fn dirname(&self) -> ~str;
fn filename(&self) -> Option<~str>;
fn filestem(&self) -> Option<~str>;
fn filetype(&self) -> Option<~str>;
pure fn with_dirname(&self, (&str)) -> Self;
pure fn with_filename(&self, (&str)) -> Self;
pure fn with_filestem(&self, (&str)) -> Self;
pure fn with_filetype(&self, (&str)) -> Self;
fn with_dirname(&self, (&str)) -> Self;
fn with_filename(&self, (&str)) -> Self;
fn with_filestem(&self, (&str)) -> Self;
fn with_filetype(&self, (&str)) -> Self;
pure fn dir_path(&self) -> Self;
pure fn file_path(&self) -> Self;
fn dir_path(&self) -> Self;
fn file_path(&self) -> Self;
pure fn push(&self, (&str)) -> Self;
pure fn push_rel(&self, (&Self)) -> Self;
pure fn push_many(&self, (&[~str])) -> Self;
pure fn pop(&self) -> Self;
fn push(&self, (&str)) -> Self;
fn push_rel(&self, (&Self)) -> Self;
fn push_many(&self, (&[~str])) -> Self;
fn pop(&self) -> Self;
pure fn unsafe_join(&self, (&Self)) -> Self;
pure fn is_restricted(&self) -> bool;
fn unsafe_join(&self, (&Self)) -> Self;
fn is_restricted(&self) -> bool;
pure fn normalize(&self) -> Self;
fn normalize(&self) -> Self;
}
#[cfg(windows)]
pub type Path = WindowsPath;
#[cfg(windows)]
pub pure fn Path(s: &str) -> Path {
pub fn Path(s: &str) -> Path {
WindowsPath(s)
}
@@ -81,7 +81,7 @@ pub trait GenericPath {
pub type Path = PosixPath;
#[cfg(unix)]
pub pure fn Path(s: &str) -> Path {
pub fn Path(s: &str) -> Path {
PosixPath(s)
}
@@ -367,7 +367,7 @@ fn get_ctime(&self) -> Option<(i64, int)> {
}
impl ToStr for PosixPath {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
let mut s = ~"";
if self.is_absolute {
s += "/";
@@ -380,14 +380,14 @@ impl ToStr for PosixPath {
// PosixPath and WindowsPath, most of their methods are common.
impl GenericPath for PosixPath {
pure fn from_str(s: &str) -> PosixPath {
fn from_str(s: &str) -> PosixPath {
let mut components = str::split_nonempty(s, |c| c == '/');
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
return PosixPath { is_absolute: is_absolute,
components: components }
}
pure fn dirname(&self) -> ~str {
fn dirname(&self) -> ~str {
unsafe {
let s = self.dir_path().to_str();
if s.len() == 0 {
@@ -398,14 +398,14 @@ impl GenericPath for PosixPath {
}
}
pure fn filename(&self) -> Option<~str> {
fn filename(&self) -> Option<~str> {
match self.components.len() {
0 => None,
n => Some(copy self.components[n - 1])
}
}
pure fn filestem(&self) -> Option<~str> {
fn filestem(&self) -> Option<~str> {
match self.filename() {
None => None,
Some(ref f) => {
@@ -417,7 +417,7 @@ impl GenericPath for PosixPath {
}
}
pure fn filetype(&self) -> Option<~str> {
fn filetype(&self) -> Option<~str> {
match self.filename() {
None => None,
Some(ref f) => {
@@ -429,7 +429,7 @@ impl GenericPath for PosixPath {
}
}
pure fn with_dirname(&self, d: &str) -> PosixPath {
fn with_dirname(&self, d: &str) -> PosixPath {
let dpath = PosixPath(d);
match self.filename() {
Some(ref f) => dpath.push(*f),
@@ -437,21 +437,21 @@ impl GenericPath for PosixPath {
}
}
pure fn with_filename(&self, f: &str) -> PosixPath {
fn with_filename(&self, f: &str) -> PosixPath {
unsafe {
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
self.dir_path().push(f)
}
}
pure fn with_filestem(&self, s: &str) -> PosixPath {
fn with_filestem(&self, s: &str) -> PosixPath {
match self.filetype() {
None => self.with_filename(s),
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
}
}
pure fn with_filetype(&self, t: &str) -> PosixPath {
fn with_filetype(&self, t: &str) -> PosixPath {
if t.len() == 0 {
match self.filestem() {
None => copy *self,
@@ -466,7 +466,7 @@ impl GenericPath for PosixPath {
}
}
pure fn dir_path(&self) -> PosixPath {
fn dir_path(&self) -> PosixPath {
if self.components.len() != 0 {
self.pop()
} else {
@@ -474,7 +474,7 @@ impl GenericPath for PosixPath {
}
}
pure fn file_path(&self) -> PosixPath {
fn file_path(&self) -> PosixPath {
let cs = match self.filename() {
None => ~[],
Some(ref f) => ~[copy *f]
@@ -483,12 +483,12 @@ impl GenericPath for PosixPath {
components: cs }
}
pure fn push_rel(&self, other: &PosixPath) -> PosixPath {
fn push_rel(&self, other: &PosixPath) -> PosixPath {
fail_unless!(!other.is_absolute);
self.push_many(other.components)
}
pure fn unsafe_join(&self, other: &PosixPath) -> PosixPath {
fn unsafe_join(&self, other: &PosixPath) -> PosixPath {
if other.is_absolute {
PosixPath { is_absolute: true,
components: copy other.components }
@@ -497,11 +497,11 @@ impl GenericPath for PosixPath {
}
}
pure fn is_restricted(&self) -> bool {
fn is_restricted(&self) -> bool {
false
}
pure fn push_many(&self, cs: &[~str]) -> PosixPath {
fn push_many(&self, cs: &[~str]) -> PosixPath {
let mut v = copy self.components;
for cs.each |e| {
let mut ss = str::split_nonempty(
@@ -513,14 +513,14 @@ impl GenericPath for PosixPath {
components: v }
}
pure fn push(&self, s: &str) -> PosixPath {
fn push(&self, s: &str) -> PosixPath {
let mut v = copy self.components;
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
unsafe { v.push_all_move(ss); }
PosixPath { components: v, ..copy *self }
}
pure fn pop(&self) -> PosixPath {
fn pop(&self) -> PosixPath {
let mut cs = copy self.components;
if cs.len() != 0 {
unsafe { cs.pop(); }
@@ -532,7 +532,7 @@ impl GenericPath for PosixPath {
//..self }
}
pure fn normalize(&self) -> PosixPath {
fn normalize(&self) -> PosixPath {
return PosixPath {
is_absolute: self.is_absolute,
components: normalize(self.components)
@@ -543,7 +543,7 @@ impl GenericPath for PosixPath {
impl ToStr for WindowsPath {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
let mut s = ~"";
match self.host {
Some(ref h) => { s += "\\\\"; s += *h; }
@@ -563,7 +563,7 @@ impl ToStr for WindowsPath {
impl GenericPath for WindowsPath {
pure fn from_str(s: &str) -> WindowsPath {
fn from_str(s: &str) -> WindowsPath {
let host;
let device;
let rest;
@@ -599,7 +599,7 @@ impl GenericPath for WindowsPath {
components: components }
}
pure fn dirname(&self) -> ~str {
fn dirname(&self) -> ~str {
unsafe {
let s = self.dir_path().to_str();
if s.len() == 0 {
@@ -610,14 +610,14 @@ impl GenericPath for WindowsPath {
}
}
pure fn filename(&self) -> Option<~str> {
fn filename(&self) -> Option<~str> {
match self.components.len() {
0 => None,
n => Some(copy self.components[n - 1])
}
}
pure fn filestem(&self) -> Option<~str> {
fn filestem(&self) -> Option<~str> {
match self.filename() {
None => None,
Some(ref f) => {
@@ -629,7 +629,7 @@ impl GenericPath for WindowsPath {
}
}
pure fn filetype(&self) -> Option<~str> {
fn filetype(&self) -> Option<~str> {
match self.filename() {
None => None,
Some(ref f) => {
@@ -641,7 +641,7 @@ impl GenericPath for WindowsPath {
}
}
pure fn with_dirname(&self, d: &str) -> WindowsPath {
fn with_dirname(&self, d: &str) -> WindowsPath {
let dpath = WindowsPath(d);
match self.filename() {
Some(ref f) => dpath.push(*f),
@@ -649,19 +649,19 @@ impl GenericPath for WindowsPath {
}
}
pure fn with_filename(&self, f: &str) -> WindowsPath {
fn with_filename(&self, f: &str) -> WindowsPath {
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
self.dir_path().push(f)
}
pure fn with_filestem(&self, s: &str) -> WindowsPath {
fn with_filestem(&self, s: &str) -> WindowsPath {
match self.filetype() {
None => self.with_filename(s),
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
}
}
pure fn with_filetype(&self, t: &str) -> WindowsPath {
fn with_filetype(&self, t: &str) -> WindowsPath {
if t.len() == 0 {
match self.filestem() {
None => copy *self,
@@ -677,7 +677,7 @@ impl GenericPath for WindowsPath {
}
}
pure fn dir_path(&self) -> WindowsPath {
fn dir_path(&self) -> WindowsPath {
if self.components.len() != 0 {
self.pop()
} else {
@@ -685,7 +685,7 @@ impl GenericPath for WindowsPath {
}
}
pure fn file_path(&self) -> WindowsPath {
fn file_path(&self) -> WindowsPath {
let cs = match self.filename() {
None => ~[],
Some(ref f) => ~[copy *f]
@@ -696,12 +696,12 @@ impl GenericPath for WindowsPath {
components: cs }
}
pure fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
fail_unless!(!other.is_absolute);
self.push_many(other.components)
}
pure fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
/* rhs not absolute is simple push */
if !other.is_absolute {
return self.push_many(other.components);
@@ -743,7 +743,7 @@ impl GenericPath for WindowsPath {
}
}
pure fn is_restricted(&self) -> bool {
fn is_restricted(&self) -> bool {
match self.filestem() {
Some(stem) => {
match stem.to_lower() {
@@ -756,7 +756,7 @@ impl GenericPath for WindowsPath {
}
}
pure fn push_many(&self, cs: &[~str]) -> WindowsPath {
fn push_many(&self, cs: &[~str]) -> WindowsPath {
let mut v = copy self.components;
for cs.each |e| {
let mut ss = str::split_nonempty(
@@ -773,14 +773,14 @@ impl GenericPath for WindowsPath {
}
}
pure fn push(&self, s: &str) -> WindowsPath {
fn push(&self, s: &str) -> WindowsPath {
let mut v = copy self.components;
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
unsafe { v.push_all_move(ss); }
return WindowsPath { components: v, ..copy *self }
}
pure fn pop(&self) -> WindowsPath {
fn pop(&self) -> WindowsPath {
let mut cs = copy self.components;
if cs.len() != 0 {
unsafe { cs.pop(); }
@@ -793,7 +793,7 @@ impl GenericPath for WindowsPath {
}
}
pure fn normalize(&self) -> WindowsPath {
fn normalize(&self) -> WindowsPath {
return WindowsPath {
host: copy self.host,
device: match self.device {
@@ -807,7 +807,7 @@ impl GenericPath for WindowsPath {
}
pub pure fn normalize(components: &[~str]) -> ~[~str] {
pub fn normalize(components: &[~str]) -> ~[~str] {
let mut cs = ~[];
unsafe {
for components.each |c| {
@@ -831,11 +831,11 @@ pub mod windows {
use option::{None, Option, Some};
#[inline(always)]
pub pure fn is_sep(u: u8) -> bool {
pub fn is_sep(u: u8) -> bool {
u == '/' as u8 || u == '\\' as u8
}
pub pure fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> {
pub fn extract_unc_prefix(s: &str) -> Option<(~str,~str)> {
if (s.len() > 1 &&
(s[0] == '\\' as u8 || s[0] == '/' as u8) &&
s[0] == s[1]) {
@@ -852,7 +852,7 @@ pub mod windows {
None
}
pub pure fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
pub fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
unsafe {
if (s.len() > 1 &&
libc::isalpha(s[0] as libc::c_int) != 0 &&
+7 -7
View File
@@ -111,10 +111,10 @@ enum State {
}
impl Eq for State {
pure fn eq(&self, other: &State) -> bool {
fn eq(&self, other: &State) -> bool {
((*self) as uint) == ((*other) as uint)
}
pure fn ne(&self, other: &State) -> bool { !(*self).eq(other) }
fn ne(&self, other: &State) -> bool { !(*self).eq(other) }
}
pub struct BufferHeader {
@@ -551,7 +551,7 @@ struct DropState {
}
/// Returns true if messages are available.
pub pure fn peek<T:Owned,Tb:Owned>(p: &RecvPacketBuffered<T, Tb>) -> bool {
pub fn peek<T:Owned,Tb:Owned>(p: &RecvPacketBuffered<T, Tb>) -> bool {
match unsafe {(*p.header()).state} {
Empty | Terminated => false,
Blocked => fail!(~"peeking on blocked packet"),
@@ -723,11 +723,11 @@ pub fn select2<A:Owned,Ab:Owned,B:Owned,Bb:Owned>(
#[doc(hidden)]
pub trait Selectable {
pure fn header(&self) -> *PacketHeader;
fn header(&self) -> *PacketHeader;
}
impl Selectable for *PacketHeader {
pure fn header(&self) -> *PacketHeader { *self }
fn header(&self) -> *PacketHeader { *self }
}
/// Returns the index of an endpoint that is ready to receive.
@@ -812,7 +812,7 @@ fn unwrap(&self) -> *Packet<T> {
option::unwrap(p)
}
pure fn header(&self) -> *PacketHeader {
fn header(&self) -> *PacketHeader {
match self.p {
Some(packet) => unsafe {
let packet = &*packet;
@@ -879,7 +879,7 @@ fn reuse_buffer(&self) -> BufferResource<Tbuffer> {
}
impl<T:Owned,Tbuffer:Owned> Selectable for RecvPacketBuffered<T, Tbuffer> {
pure fn header(&self) -> *PacketHeader {
fn header(&self) -> *PacketHeader {
match self.p {
Some(packet) => unsafe {
let packet = &*packet;
+34 -34
View File
@@ -51,11 +51,11 @@ pub mod rusti {
/// Get an unsafe pointer to a value
#[inline(always)]
pub pure fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
pub fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
/// Calculate the offset from a pointer
#[inline(always)]
pub pure fn offset<T>(ptr: *T, count: uint) -> *T {
pub fn offset<T>(ptr: *T, count: uint) -> *T {
unsafe {
(ptr as uint + count * sys::size_of::<T>()) as *T
}
@@ -63,7 +63,7 @@ pub mod rusti {
/// Calculate the offset from a const pointer
#[inline(always)]
pub pure fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
pub fn const_offset<T>(ptr: *const T, count: uint) -> *const T {
unsafe {
(ptr as uint + count * sys::size_of::<T>()) as *T
}
@@ -71,7 +71,7 @@ pub mod rusti {
/// Calculate the offset from a mut pointer
#[inline(always)]
pub pure fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
pub fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
(ptr as uint + count * sys::size_of::<T>()) as *mut T
}
@@ -93,19 +93,19 @@ pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
/// Create an unsafe null pointer
#[inline(always)]
pub pure fn null<T>() -> *T { unsafe { cast::reinterpret_cast(&0u) } }
pub fn null<T>() -> *T { unsafe { cast::reinterpret_cast(&0u) } }
/// Create an unsafe mutable null pointer
#[inline(always)]
pub pure fn mut_null<T>() -> *mut T { unsafe { cast::reinterpret_cast(&0u) } }
pub fn mut_null<T>() -> *mut T { unsafe { cast::reinterpret_cast(&0u) } }
/// Returns true if the pointer is equal to the null pointer.
#[inline(always)]
pub pure fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
pub fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
/// Returns true if the pointer is not equal to the null pointer.
#[inline(always)]
pub pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
pub fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
/**
* Copies data from one location to another
@@ -138,7 +138,7 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
reinterpret_cast.
*/
#[inline(always)]
pub pure fn to_unsafe_ptr<T>(thing: &T) -> *T {
pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
unsafe { cast::reinterpret_cast(&thing) }
}
@@ -148,7 +148,7 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
reinterpret_cast.
*/
#[inline(always)]
pub pure fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
unsafe { cast::reinterpret_cast(&thing) }
}
@@ -158,7 +158,7 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
reinterpret_cast.
*/
#[inline(always)]
pub pure fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
unsafe { cast::reinterpret_cast(&thing) }
}
@@ -170,7 +170,7 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
(I couldn't think of a cutesy name for this one.)
*/
#[inline(always)]
pub pure fn to_uint<T>(thing: &T) -> uint {
pub fn to_uint<T>(thing: &T) -> uint {
unsafe {
cast::reinterpret_cast(&thing)
}
@@ -178,7 +178,7 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
/// Determine if two borrowed pointers point to the same thing.
#[inline(always)]
pub pure fn ref_eq<T>(thing: &'a T, other: &'b T) -> bool {
pub fn ref_eq<T>(thing: &'a T, other: &'b T) -> bool {
to_uint(thing) == to_uint(other)
}
@@ -223,46 +223,46 @@ pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) {
}
pub trait Ptr<T> {
pure fn is_null(&const self) -> bool;
pure fn is_not_null(&const self) -> bool;
pure fn offset(&self, count: uint) -> Self;
fn is_null(&const self) -> bool;
fn is_not_null(&const self) -> bool;
fn offset(&self, count: uint) -> Self;
}
/// Extension methods for immutable pointers
impl<T> Ptr<T> for *T {
/// Returns true if the pointer is equal to the null pointer.
#[inline(always)]
pure fn is_null(&const self) -> bool { is_null(*self) }
fn is_null(&const self) -> bool { is_null(*self) }
/// Returns true if the pointer is not equal to the null pointer.
#[inline(always)]
pure fn is_not_null(&const self) -> bool { is_not_null(*self) }
fn is_not_null(&const self) -> bool { is_not_null(*self) }
/// Calculates the offset from a pointer.
#[inline(always)]
pure fn offset(&self, count: uint) -> *T { offset(*self, count) }
fn offset(&self, count: uint) -> *T { offset(*self, count) }
}
/// Extension methods for mutable pointers
impl<T> Ptr<T> for *mut T {
/// Returns true if the pointer is equal to the null pointer.
#[inline(always)]
pure fn is_null(&const self) -> bool { is_null(*self) }
fn is_null(&const self) -> bool { is_null(*self) }
/// Returns true if the pointer is not equal to the null pointer.
#[inline(always)]
pure fn is_not_null(&const self) -> bool { is_not_null(*self) }
fn is_not_null(&const self) -> bool { is_not_null(*self) }
/// Calculates the offset from a mutable pointer.
#[inline(always)]
pure fn offset(&self, count: uint) -> *mut T { mut_offset(*self, count) }
fn offset(&self, count: uint) -> *mut T { mut_offset(*self, count) }
}
// Equality for pointers
#[cfg(notest)]
impl<T> Eq for *const T {
#[inline(always)]
pure fn eq(&self, other: &*const T) -> bool {
fn eq(&self, other: &*const T) -> bool {
unsafe {
let a: uint = cast::reinterpret_cast(&(*self));
let b: uint = cast::reinterpret_cast(&(*other));
@@ -270,14 +270,14 @@ impl<T> Eq for *const T {
}
}
#[inline(always)]
pure fn ne(&self, other: &*const T) -> bool { !(*self).eq(other) }
fn ne(&self, other: &*const T) -> bool { !(*self).eq(other) }
}
// Comparison for pointers
#[cfg(notest)]
impl<T> Ord for *const T {
#[inline(always)]
pure fn lt(&self, other: &*const T) -> bool {
fn lt(&self, other: &*const T) -> bool {
unsafe {
let a: uint = cast::reinterpret_cast(&(*self));
let b: uint = cast::reinterpret_cast(&(*other));
@@ -285,7 +285,7 @@ impl<T> Ord for *const T {
}
}
#[inline(always)]
pure fn le(&self, other: &*const T) -> bool {
fn le(&self, other: &*const T) -> bool {
unsafe {
let a: uint = cast::reinterpret_cast(&(*self));
let b: uint = cast::reinterpret_cast(&(*other));
@@ -293,7 +293,7 @@ impl<T> Ord for *const T {
}
}
#[inline(always)]
pure fn ge(&self, other: &*const T) -> bool {
fn ge(&self, other: &*const T) -> bool {
unsafe {
let a: uint = cast::reinterpret_cast(&(*self));
let b: uint = cast::reinterpret_cast(&(*other));
@@ -301,7 +301,7 @@ impl<T> Ord for *const T {
}
}
#[inline(always)]
pure fn gt(&self, other: &*const T) -> bool {
fn gt(&self, other: &*const T) -> bool {
unsafe {
let a: uint = cast::reinterpret_cast(&(*self));
let b: uint = cast::reinterpret_cast(&(*other));
@@ -314,11 +314,11 @@ impl<T> Ord for *const T {
#[cfg(notest)]
impl<T:Eq> Eq for &'self const T {
#[inline(always)]
pure fn eq(&self, other: & &'self const T) -> bool {
fn eq(&self, other: & &'self const T) -> bool {
return *(*self) == *(*other);
}
#[inline(always)]
pure fn ne(&self, other: & &'self const T) -> bool {
fn ne(&self, other: & &'self const T) -> bool {
return *(*self) != *(*other);
}
}
@@ -327,19 +327,19 @@ impl<T:Eq> Eq for &'self const T {
#[cfg(notest)]
impl<T:Ord> Ord for &'self const T {
#[inline(always)]
pure fn lt(&self, other: & &'self const T) -> bool {
fn lt(&self, other: & &'self const T) -> bool {
*(*self) < *(*other)
}
#[inline(always)]
pure fn le(&self, other: & &'self const T) -> bool {
fn le(&self, other: & &'self const T) -> bool {
*(*self) <= *(*other)
}
#[inline(always)]
pure fn ge(&self, other: & &'self const T) -> bool {
fn ge(&self, other: & &'self const T) -> bool {
*(*self) >= *(*other)
}
#[inline(always)]
pure fn gt(&self, other: & &'self const T) -> bool {
fn gt(&self, other: & &'self const T) -> bool {
*(*self) > *(*other)
}
}
+2 -2
View File
@@ -527,12 +527,12 @@ fn next(&self) -> u32 {
}
}
pub pure fn xorshift() -> @Rng {
pub fn xorshift() -> @Rng {
// constants taken from http://en.wikipedia.org/wiki/Xorshift
seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32)
}
pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> @Rng {
pub fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> @Rng {
@XorShiftState { x: x, y: y, z: z, w: w } as @Rng
}
+27 -27
View File
@@ -36,7 +36,7 @@ pub enum Result<T, U> {
* If the result is an error
*/
#[inline(always)]
pub pure fn get<T:Copy,U>(res: &Result<T, U>) -> T {
pub fn get<T:Copy,U>(res: &Result<T, U>) -> T {
match *res {
Ok(copy t) => t,
Err(ref the_err) => unsafe {
@@ -53,7 +53,7 @@ pub enum Result<T, U> {
* If the result is an error
*/
#[inline(always)]
pub pure fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T {
pub fn get_ref<T, U>(res: &'a Result<T, U>) -> &'a T {
match *res {
Ok(ref t) => t,
Err(ref the_err) => unsafe {
@@ -70,7 +70,7 @@ pub enum Result<T, U> {
* If the result is not an error
*/
#[inline(always)]
pub pure fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
pub fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
match *res {
Err(copy u) => u,
Ok(_) => fail!(~"get_err called on ok result")
@@ -79,7 +79,7 @@ pub enum Result<T, U> {
/// Returns true if the result is `ok`
#[inline(always)]
pub pure fn is_ok<T, U>(res: &Result<T, U>) -> bool {
pub fn is_ok<T, U>(res: &Result<T, U>) -> bool {
match *res {
Ok(_) => true,
Err(_) => false
@@ -88,7 +88,7 @@ pub enum Result<T, U> {
/// Returns true if the result is `err`
#[inline(always)]
pub pure fn is_err<T, U>(res: &Result<T, U>) -> bool {
pub fn is_err<T, U>(res: &Result<T, U>) -> bool {
!is_ok(res)
}
@@ -99,7 +99,7 @@ pub enum Result<T, U> {
* result variants are converted to `either::left`.
*/
#[inline(always)]
pub pure fn to_either<T:Copy,U:Copy>(res: &Result<U, T>)
pub fn to_either<T:Copy,U:Copy>(res: &Result<U, T>)
-> Either<T, U> {
match *res {
Ok(copy res) => either::Right(res),
@@ -122,7 +122,7 @@ pub enum Result<T, U> {
* }
*/
#[inline(always)]
pub pure fn chain<T, U, V>(res: Result<T, V>, op: &fn(T)
pub fn chain<T, U, V>(res: Result<T, V>, op: &fn(T)
-> Result<U, V>) -> Result<U, V> {
match res {
Ok(t) => op(t),
@@ -139,7 +139,7 @@ pub enum Result<T, U> {
* successful result while handling an error.
*/
#[inline(always)]
pub pure fn chain_err<T, U, V>(
pub fn chain_err<T, U, V>(
res: Result<T, V>,
op: &fn(t: V) -> Result<T, U>)
-> Result<T, U> {
@@ -164,7 +164,7 @@ pub enum Result<T, U> {
* }
*/
#[inline(always)]
pub pure fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
pub fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
match *res {
Ok(ref t) => f(t),
Err(_) => ()
@@ -180,7 +180,7 @@ pub enum Result<T, U> {
* handling an error.
*/
#[inline(always)]
pub pure fn iter_err<T, E>(res: &Result<T, E>, f: &fn(&E)) {
pub fn iter_err<T, E>(res: &Result<T, E>, f: &fn(&E)) {
match *res {
Ok(_) => (),
Err(ref e) => f(e)
@@ -202,7 +202,7 @@ pub enum Result<T, U> {
* }
*/
#[inline(always)]
pub pure fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: &fn(&T) -> U)
pub fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: &fn(&T) -> U)
-> Result<U, E> {
match *res {
Ok(ref t) => Ok(op(t)),
@@ -219,7 +219,7 @@ pub enum Result<T, U> {
* successful result while handling an error.
*/
#[inline(always)]
pub pure fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
pub fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
-> Result<T, F> {
match *res {
Ok(copy t) => Ok(t),
@@ -229,53 +229,53 @@ pub enum Result<T, U> {
pub impl<T, E> Result<T, E> {
#[inline(always)]
pure fn get_ref(&self) -> &'self T { get_ref(self) }
fn get_ref(&self) -> &'self T { get_ref(self) }
#[inline(always)]
pure fn is_ok(&self) -> bool { is_ok(self) }
fn is_ok(&self) -> bool { is_ok(self) }
#[inline(always)]
pure fn is_err(&self) -> bool { is_err(self) }
fn is_err(&self) -> bool { is_err(self) }
#[inline(always)]
pure fn iter(&self, f: &fn(&T)) { iter(self, f) }
fn iter(&self, f: &fn(&T)) { iter(self, f) }
#[inline(always)]
pure fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) }
fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) }
#[inline(always)]
pure fn unwrap(self) -> T { unwrap(self) }
fn unwrap(self) -> T { unwrap(self) }
#[inline(always)]
pure fn unwrap_err(self) -> E { unwrap_err(self) }
fn unwrap_err(self) -> E { unwrap_err(self) }
#[inline(always)]
pure fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
chain(self, op)
}
#[inline(always)]
pure fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
chain_err(self, op)
}
}
pub impl<T:Copy,E> Result<T, E> {
#[inline(always)]
pure fn get(&self) -> T { get(self) }
fn get(&self) -> T { get(self) }
#[inline(always)]
pure fn map_err<F:Copy>(&self, op: &fn(&E) -> F) -> Result<T,F> {
fn map_err<F:Copy>(&self, op: &fn(&E) -> F) -> Result<T,F> {
map_err(self, op)
}
}
pub impl<T, E: Copy> Result<T, E> {
#[inline(always)]
pure fn get_err(&self) -> E { get_err(self) }
fn get_err(&self) -> E { get_err(self) }
#[inline(always)]
pure fn map<U:Copy>(&self, op: &fn(&T) -> U) -> Result<U,E> {
fn map<U:Copy>(&self, op: &fn(&T) -> U) -> Result<U,E> {
map(self, op)
}
}
@@ -375,7 +375,7 @@ pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
/// Unwraps a result, assuming it is an `ok(T)`
#[inline(always)]
pub pure fn unwrap<T, U>(res: Result<T, U>) -> T {
pub fn unwrap<T, U>(res: Result<T, U>) -> T {
match res {
Ok(t) => t,
Err(_) => fail!(~"unwrap called on an err result")
@@ -384,7 +384,7 @@ pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
/// Unwraps a result, assuming it is an `err(U)`
#[inline(always)]
pub pure fn unwrap_err<T, U>(res: Result<T, U>) -> U {
pub fn unwrap_err<T, U>(res: Result<T, U>) -> U {
match res {
Err(u) => u,
Ok(_) => fail!(~"unwrap called on an ok result")
+1 -1
View File
@@ -184,7 +184,7 @@ fn align_down(sp: *mut uint) -> *mut uint {
// XXX: ptr::offset is positive ints only
#[inline(always)]
pub pure fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
pub fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
use core::sys::size_of;
unsafe {
(ptr as int + count * (size_of::<T>() as int)) as *mut T
+3 -3
View File
@@ -518,7 +518,7 @@ fn native_handle(&self) -> *uvll::uv_write_t {
impl UvError {
pure fn name(&self) -> ~str {
fn name(&self) -> ~str {
unsafe {
let inner = match self { &UvError(ref a) => a };
let name_str = uvll::err_name(inner);
@@ -527,7 +527,7 @@ impl UvError {
}
}
pure fn desc(&self) -> ~str {
fn desc(&self) -> ~str {
unsafe {
let inner = match self { &UvError(ref a) => a };
let desc_str = uvll::strerror(inner);
@@ -538,7 +538,7 @@ impl UvError {
}
impl ToStr for UvError {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
fmt!("%s: %s", self.name(), self.desc())
}
}
+216 -216
View File
@@ -44,27 +44,27 @@
*
* Fails if invalid UTF-8
*/
pub pure fn from_bytes(vv: &[const u8]) -> ~str {
pub fn from_bytes(vv: &[const u8]) -> ~str {
fail_unless!(is_utf8(vv));
return unsafe { raw::from_bytes(vv) };
}
/// Copy a slice into a new unique str
pub pure fn from_slice(s: &str) -> ~str {
pub fn from_slice(s: &str) -> ~str {
unsafe { raw::slice_bytes_unique(s, 0, len(s)) }
}
impl ToStr for ~str {
#[inline(always)]
pure fn to_str(&self) -> ~str { copy *self }
fn to_str(&self) -> ~str { copy *self }
}
impl ToStr for &'self str {
#[inline(always)]
pure fn to_str(&self) -> ~str { ::str::from_slice(*self) }
fn to_str(&self) -> ~str { ::str::from_slice(*self) }
}
impl ToStr for @str {
#[inline(always)]
pure fn to_str(&self) -> ~str { ::str::from_slice(*self) }
fn to_str(&self) -> ~str { ::str::from_slice(*self) }
}
/**
@@ -74,7 +74,7 @@ impl ToStr for @str {
*
* Fails if invalid UTF-8
*/
pub pure fn from_byte(b: u8) -> ~str {
pub fn from_byte(b: u8) -> ~str {
fail_unless!(b < 128u8);
unsafe { ::cast::transmute(~[b, 0u8]) }
}
@@ -151,14 +151,14 @@ pub fn push_char(s: &mut ~str, ch: char) {
}
/// Convert a char to a string
pub pure fn from_char(ch: char) -> ~str {
pub fn from_char(ch: char) -> ~str {
let mut buf = ~"";
unsafe { push_char(&mut buf, ch); }
buf
}
/// Convert a vector of chars to a string
pub pure fn from_chars(chs: &[char]) -> ~str {
pub fn from_chars(chs: &[char]) -> ~str {
let mut buf = ~"";
unsafe {
reserve(&mut buf, chs.len());
@@ -206,7 +206,7 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
/// Concatenate two strings together
#[inline(always)]
pub pure fn append(lhs: ~str, rhs: &str) -> ~str {
pub fn append(lhs: ~str, rhs: &str) -> ~str {
let mut v = lhs;
unsafe {
push_str_no_overallocate(&mut v, rhs);
@@ -216,7 +216,7 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
/// Concatenate a vector of strings
pub pure fn concat(v: &[~str]) -> ~str {
pub fn concat(v: &[~str]) -> ~str {
let mut s: ~str = ~"";
for vec::each(v) |ss| {
unsafe { push_str(&mut s, *ss) };
@@ -225,7 +225,7 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
}
/// Concatenate a vector of strings, placing a given separator between each
pub pure fn connect(v: &[~str], sep: &str) -> ~str {
pub fn connect(v: &[~str], sep: &str) -> ~str {
let mut s = ~"", first = true;
for vec::each(v) |ss| {
if first { first = false; } else { unsafe { push_str(&mut s, sep); } }
@@ -235,7 +235,7 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
}
/// Concatenate a vector of strings, placing a given separator between each
pub pure fn connect_slices(v: &[&str], sep: &str) -> ~str {
pub fn connect_slices(v: &[&str], sep: &str) -> ~str {
let mut s = ~"", first = true;
for vec::each(v) |ss| {
if first { first = false; } else { unsafe { push_str(&mut s, sep); } }
@@ -245,7 +245,7 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
}
/// Given a string, make a new string with repeated copies of it
pub pure fn repeat(ss: &str, nn: uint) -> ~str {
pub fn repeat(ss: &str, nn: uint) -> ~str {
let mut acc = ~"";
for nn.times { acc += ss; }
acc
@@ -313,7 +313,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* * chars_to_trim - A vector of chars
*
*/
pub pure fn trim_left_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
pub fn trim_left_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
if chars_to_trim.is_empty() { return s; }
match find(s, |c| !chars_to_trim.contains(&c)) {
@@ -331,7 +331,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* * chars_to_trim - A vector of chars
*
*/
pub pure fn trim_right_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
pub fn trim_right_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
if chars_to_trim.is_empty() { return s; }
match rfind(s, |c| !chars_to_trim.contains(&c)) {
@@ -352,12 +352,12 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* * chars_to_trim - A vector of chars
*
*/
pub pure fn trim_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
pub fn trim_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
trim_left_chars(trim_right_chars(s, chars_to_trim), chars_to_trim)
}
/// Returns a string with leading whitespace removed
pub pure fn trim_left(s: &'a str) -> &'a str {
pub fn trim_left(s: &'a str) -> &'a str {
match find(s, |c| !char::is_whitespace(c)) {
None => "",
Some(first) => unsafe { raw::slice_bytes(s, first, len(s)) }
@@ -365,7 +365,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
}
/// Returns a string with trailing whitespace removed
pub pure fn trim_right(s: &'a str) -> &'a str {
pub fn trim_right(s: &'a str) -> &'a str {
match rfind(s, |c| !char::is_whitespace(c)) {
None => "",
Some(last) => {
@@ -376,7 +376,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
}
/// Returns a string with leading and trailing whitespace removed
pub pure fn trim(s: &'a str) -> &'a str { trim_left(trim_right(s)) }
pub fn trim(s: &'a str) -> &'a str { trim_left(trim_right(s)) }
/*
Section: Transforming strings
@@ -387,7 +387,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
*
* The result vector is not null-terminated.
*/
pub pure fn to_bytes(s: &str) -> ~[u8] {
pub fn to_bytes(s: &str) -> ~[u8] {
unsafe {
let mut v: ~[u8] = ::cast::transmute(from_slice(s));
vec::raw::set_len(&mut v, len(s));
@@ -397,14 +397,14 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
/// Work with the string as a byte slice, not including trailing null.
#[inline(always)]
pub pure fn byte_slice<T>(s: &str, f: &fn(v: &[u8]) -> T) -> T {
pub fn byte_slice<T>(s: &str, f: &fn(v: &[u8]) -> T) -> T {
do as_buf(s) |p,n| {
unsafe { vec::raw::buf_as_slice(p, n-1u, f) }
}
}
/// Convert a string to a vector of characters
pub pure fn chars(s: &str) -> ~[char] {
pub fn chars(s: &str) -> ~[char] {
let mut buf = ~[], i = 0;
let len = len(s);
while i < len {
@@ -421,7 +421,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* Returns a string containing `n` characters starting at byte offset
* `begin`.
*/
pub pure fn substr(s: &'a str, begin: uint, n: uint) -> &'a str {
pub fn substr(s: &'a str, begin: uint, n: uint) -> &'a str {
slice(s, begin, begin + count_bytes(s, begin, n))
}
@@ -431,7 +431,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* Fails when `begin` and `end` do not point to valid characters or beyond
* the last character of the string
*/
pub pure fn slice(s: &'a str, begin: uint, end: uint) -> &'a str {
pub fn slice(s: &'a str, begin: uint, end: uint) -> &'a str {
fail_unless!(is_char_boundary(s, begin));
fail_unless!(is_char_boundary(s, end));
unsafe { raw::slice_bytes(s, begin, end) }
@@ -439,7 +439,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
/// Splits a string into substrings at each occurrence of a given
/// character.
pub pure fn split_char(s: &str, sep: char) -> ~[~str] {
pub fn split_char(s: &str, sep: char) -> ~[~str] {
split_char_inner(s, sep, len(s), true, true)
}
@@ -449,12 +449,12 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
*
* The byte must be a valid UTF-8/ASCII byte
*/
pub pure fn splitn_char(s: &str, sep: char, count: uint) -> ~[~str] {
pub fn splitn_char(s: &str, sep: char, count: uint) -> ~[~str] {
split_char_inner(s, sep, count, true, true)
}
/// Like `split_char`, but omits empty strings from the returned vector
pub pure fn split_char_nonempty(s: &str, sep: char) -> ~[~str] {
pub fn split_char_nonempty(s: &str, sep: char) -> ~[~str] {
split_char_inner(s, sep, len(s), false, false)
}
@@ -462,12 +462,12 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* Like `split_char`, but a trailing empty string is omitted
* (e.g. `split_char_no_trailing("A B ",' ') == ~[~"A",~"B"]`)
*/
pub pure fn split_char_no_trailing(s: &str, sep: char) -> ~[~str] {
pub fn split_char_no_trailing(s: &str, sep: char) -> ~[~str] {
split_char_inner(s, sep, len(s), true, false)
}
pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool,
allow_trailing_empty: bool) -> ~[~str] {
fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool,
allow_trailing_empty: bool) -> ~[~str] {
if sep < 128u as char {
let b = sep as u8, l = len(s);
let mut result = ~[], done = 0u;
@@ -496,7 +496,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
/// Splits a string into substrings using a character function
pub pure fn split(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] {
pub fn split(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] {
split_inner(s, sepfn, len(s), true, true)
}
@@ -504,7 +504,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* Splits a string into substrings using a character function, cutting at
* most `count` times.
*/
pub pure fn splitn(s: &str,
pub fn splitn(s: &str,
sepfn: &fn(char) -> bool,
count: uint)
-> ~[~str] {
@@ -512,7 +512,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
}
/// Like `split`, but omits empty strings from the returned vector
pub pure fn split_nonempty(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] {
pub fn split_nonempty(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] {
split_inner(s, sepfn, len(s), false, false)
}
@@ -521,7 +521,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* Like `split`, but a trailing empty string is omitted
* (e.g. `split_no_trailing("A B ",' ') == ~[~"A",~"B"]`)
*/
pub pure fn split_no_trailing(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] {
pub fn split_no_trailing(s: &str, sepfn: &fn(char) -> bool) -> ~[~str] {
split_inner(s, sepfn, len(s), true, false)
}
@@ -551,7 +551,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
}
// See Issue #1932 for why this is a naive search
pure fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) {
fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) {
let sep_len = len(sep), l = len(s);
fail_unless!(sep_len > 0u);
let mut i = 0u, match_start = 0u, match_i = 0u;
@@ -578,7 +578,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
}
}
pure fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) {
fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) {
let mut last_end = 0u;
do iter_matches(s, sep) |from, to| {
f(last_end, from);
@@ -596,7 +596,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
* fail_unless!(["", "XXX", "YYY", ""] == split_str(".XXX.YYY.", "."))
* ~~~
*/
pub pure fn split_str(s: &'a str, sep: &'b str) -> ~[~str] {
pub fn split_str(s: &'a str, sep: &'b str) -> ~[~str] {
let mut result = ~[];
do iter_between_matches(s, sep) |from, to| {
unsafe { result.push(raw::slice_bytes_unique(s, from, to)); }
@@ -604,7 +604,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
result
}
pub pure fn split_str_nonempty(s: &'a str, sep: &'b str) -> ~[~str] {
pub fn split_str_nonempty(s: &'a str, sep: &'b str) -> ~[~str] {
let mut result = ~[];
do iter_between_matches(s, sep) |from, to| {
if to > from {
@@ -651,7 +651,7 @@ pub fn levdistance(s: &str, t: &str) -> uint {
/**
* Splits a string into a vector of the substrings separated by LF ('\n').
*/
pub pure fn lines(s: &str) -> ~[~str] {
pub fn lines(s: &str) -> ~[~str] {
split_char_no_trailing(s, '\n')
}
@@ -659,7 +659,7 @@ pub fn levdistance(s: &str, t: &str) -> uint {
* Splits a string into a vector of the substrings separated by LF ('\n')
* and/or CR LF ("\r\n")
*/
pub pure fn lines_any(s: &str) -> ~[~str] {
pub fn lines_any(s: &str) -> ~[~str] {
vec::map(lines(s), |s| {
let l = len(*s);
let mut cp = copy *s;
@@ -671,7 +671,7 @@ pub fn levdistance(s: &str, t: &str) -> uint {
}
/// Splits a string into a vector of the substrings separated by whitespace
pub pure fn words(s: &str) -> ~[~str] {
pub fn words(s: &str) -> ~[~str] {
split_nonempty(s, char::is_whitespace)
}
@@ -710,14 +710,14 @@ pub fn split_within(ss: &str, lim: uint) -> ~[~str] {
/// Convert a string to lowercase. ASCII only
pub pure fn to_lower(s: &str) -> ~str {
pub fn to_lower(s: &str) -> ~str {
map(s,
|c| unsafe{(libc::tolower(c as libc::c_char)) as char}
)
}
/// Convert a string to uppercase. ASCII only
pub pure fn to_upper(s: &str) -> ~str {
pub fn to_upper(s: &str) -> ~str {
map(s,
|c| unsafe{(libc::toupper(c as libc::c_char)) as char}
)
@@ -736,7 +736,7 @@ pub fn split_within(ss: &str, lim: uint) -> ~[~str] {
*
* The original string with all occurances of `from` replaced with `to`
*/
pub pure fn replace(s: &str, from: &str, to: &str) -> ~str {
pub fn replace(s: &str, from: &str, to: &str) -> ~str {
let mut result = ~"", first = true;
do iter_between_matches(s, from) |start, end| {
if first {
@@ -756,7 +756,7 @@ pub fn split_within(ss: &str, lim: uint) -> ~[~str] {
/// Bytewise slice equality
#[cfg(notest)]
#[lang="str_eq"]
pub pure fn eq_slice(a: &str, b: &str) -> bool {
pub fn eq_slice(a: &str, b: &str) -> bool {
do as_buf(a) |ap, alen| {
do as_buf(b) |bp, blen| {
if (alen != blen) { false }
@@ -772,7 +772,7 @@ pub fn split_within(ss: &str, lim: uint) -> ~[~str] {
}
#[cfg(test)]
pub pure fn eq_slice(a: &str, b: &str) -> bool {
pub fn eq_slice(a: &str, b: &str) -> bool {
do as_buf(a) |ap, alen| {
do as_buf(b) |bp, blen| {
if (alen != blen) { false }
@@ -790,16 +790,16 @@ pub fn split_within(ss: &str, lim: uint) -> ~[~str] {
/// Bytewise string equality
#[cfg(notest)]
#[lang="uniq_str_eq"]
pub pure fn eq(a: &~str, b: &~str) -> bool {
pub fn eq(a: &~str, b: &~str) -> bool {
eq_slice(*a, *b)
}
#[cfg(test)]
pub pure fn eq(a: &~str, b: &~str) -> bool {
pub fn eq(a: &~str, b: &~str) -> bool {
eq_slice(*a, *b)
}
pure fn cmp(a: &str, b: &str) -> Ordering {
fn cmp(a: &str, b: &str) -> Ordering {
let low = uint::min(a.len(), b.len());
for uint::range(0, low) |idx| {
@@ -815,21 +815,21 @@ pub fn split_within(ss: &str, lim: uint) -> ~[~str] {
#[cfg(notest)]
impl TotalOrd for &'self str {
pure fn cmp(&self, other: & &'self str) -> Ordering { cmp(*self, *other) }
fn cmp(&self, other: & &'self str) -> Ordering { cmp(*self, *other) }
}
#[cfg(notest)]
impl TotalOrd for ~str {
pure fn cmp(&self, other: &~str) -> Ordering { cmp(*self, *other) }
fn cmp(&self, other: &~str) -> Ordering { cmp(*self, *other) }
}
#[cfg(notest)]
impl TotalOrd for @str {
pure fn cmp(&self, other: &@str) -> Ordering { cmp(*self, *other) }
fn cmp(&self, other: &@str) -> Ordering { cmp(*self, *other) }
}
/// Bytewise slice less than
pure fn lt(a: &str, b: &str) -> bool {
fn lt(a: &str, b: &str) -> bool {
let (a_len, b_len) = (a.len(), b.len());
let mut end = uint::min(a_len, b_len);
@@ -845,90 +845,90 @@ impl TotalOrd for @str {
}
/// Bytewise less than or equal
pub pure fn le(a: &str, b: &str) -> bool {
pub fn le(a: &str, b: &str) -> bool {
!lt(b, a)
}
/// Bytewise greater than or equal
pure fn ge(a: &str, b: &str) -> bool {
fn ge(a: &str, b: &str) -> bool {
!lt(a, b)
}
/// Bytewise greater than
pure fn gt(a: &str, b: &str) -> bool {
fn gt(a: &str, b: &str) -> bool {
!le(a, b)
}
#[cfg(notest)]
impl Eq for &'self str {
#[inline(always)]
pure fn eq(&self, other: & &'self str) -> bool {
fn eq(&self, other: & &'self str) -> bool {
eq_slice((*self), (*other))
}
#[inline(always)]
pure fn ne(&self, other: & &'self str) -> bool { !(*self).eq(other) }
fn ne(&self, other: & &'self str) -> bool { !(*self).eq(other) }
}
#[cfg(notest)]
impl Eq for ~str {
#[inline(always)]
pure fn eq(&self, other: &~str) -> bool {
fn eq(&self, other: &~str) -> bool {
eq_slice((*self), (*other))
}
#[inline(always)]
pure fn ne(&self, other: &~str) -> bool { !(*self).eq(other) }
fn ne(&self, other: &~str) -> bool { !(*self).eq(other) }
}
#[cfg(notest)]
impl Eq for @str {
#[inline(always)]
pure fn eq(&self, other: &@str) -> bool {
fn eq(&self, other: &@str) -> bool {
eq_slice((*self), (*other))
}
#[inline(always)]
pure fn ne(&self, other: &@str) -> bool { !(*self).eq(other) }
fn ne(&self, other: &@str) -> bool { !(*self).eq(other) }
}
#[cfg(notest)]
impl Ord for ~str {
#[inline(always)]
pure fn lt(&self, other: &~str) -> bool { lt((*self), (*other)) }
fn lt(&self, other: &~str) -> bool { lt((*self), (*other)) }
#[inline(always)]
pure fn le(&self, other: &~str) -> bool { le((*self), (*other)) }
fn le(&self, other: &~str) -> bool { le((*self), (*other)) }
#[inline(always)]
pure fn ge(&self, other: &~str) -> bool { ge((*self), (*other)) }
fn ge(&self, other: &~str) -> bool { ge((*self), (*other)) }
#[inline(always)]
pure fn gt(&self, other: &~str) -> bool { gt((*self), (*other)) }
fn gt(&self, other: &~str) -> bool { gt((*self), (*other)) }
}
#[cfg(notest)]
impl Ord for &'self str {
#[inline(always)]
pure fn lt(&self, other: & &'self str) -> bool { lt((*self), (*other)) }
fn lt(&self, other: & &'self str) -> bool { lt((*self), (*other)) }
#[inline(always)]
pure fn le(&self, other: & &'self str) -> bool { le((*self), (*other)) }
fn le(&self, other: & &'self str) -> bool { le((*self), (*other)) }
#[inline(always)]
pure fn ge(&self, other: & &'self str) -> bool { ge((*self), (*other)) }
fn ge(&self, other: & &'self str) -> bool { ge((*self), (*other)) }
#[inline(always)]
pure fn gt(&self, other: & &'self str) -> bool { gt((*self), (*other)) }
fn gt(&self, other: & &'self str) -> bool { gt((*self), (*other)) }
}
#[cfg(notest)]
impl Ord for @str {
#[inline(always)]
pure fn lt(&self, other: &@str) -> bool { lt((*self), (*other)) }
fn lt(&self, other: &@str) -> bool { lt((*self), (*other)) }
#[inline(always)]
pure fn le(&self, other: &@str) -> bool { le((*self), (*other)) }
fn le(&self, other: &@str) -> bool { le((*self), (*other)) }
#[inline(always)]
pure fn ge(&self, other: &@str) -> bool { ge((*self), (*other)) }
fn ge(&self, other: &@str) -> bool { ge((*self), (*other)) }
#[inline(always)]
pure fn gt(&self, other: &@str) -> bool { gt((*self), (*other)) }
fn gt(&self, other: &@str) -> bool { gt((*self), (*other)) }
}
#[cfg(notest)]
impl Equiv<~str> for &'self str {
#[inline(always)]
pure fn equiv(&self, other: &~str) -> bool { eq_slice(*self, *other) }
fn equiv(&self, other: &~str) -> bool { eq_slice(*self, *other) }
}
/*
@@ -939,7 +939,7 @@ impl Equiv<~str> for &'self str {
* Return true if a predicate matches all characters or if the string
* contains no characters
*/
pub pure fn all(s: &str, it: &fn(char) -> bool) -> bool {
pub fn all(s: &str, it: &fn(char) -> bool) -> bool {
all_between(s, 0u, len(s), it)
}
@@ -947,12 +947,12 @@ impl Equiv<~str> for &'self str {
* Return true if a predicate matches any character (and false if it
* matches none or there are no characters)
*/
pub pure fn any(ss: &str, pred: &fn(char) -> bool) -> bool {
pub fn any(ss: &str, pred: &fn(char) -> bool) -> bool {
!all(ss, |cc| !pred(cc))
}
/// Apply a function to each character
pub pure fn map(ss: &str, ff: &fn(char) -> char) -> ~str {
pub fn map(ss: &str, ff: &fn(char) -> char) -> ~str {
let mut result = ~"";
unsafe {
reserve(&mut result, len(ss));
@@ -965,13 +965,13 @@ impl Equiv<~str> for &'self str {
/// Iterate over the bytes in a string
#[inline(always)]
pub pure fn each(s: &str, it: &fn(u8) -> bool) {
pub fn each(s: &str, it: &fn(u8) -> bool) {
eachi(s, |_i, b| it(b))
}
/// Iterate over the bytes in a string, with indices
#[inline(always)]
pub pure fn eachi(s: &str, it: &fn(uint, u8) -> bool) {
pub fn eachi(s: &str, it: &fn(uint, u8) -> bool) {
let mut pos = 0;
let len = s.len();
@@ -983,13 +983,13 @@ impl Equiv<~str> for &'self str {
/// Iterate over the bytes in a string in reverse
#[inline(always)]
pub pure fn each_reverse(s: &str, it: &fn(u8) -> bool) {
pub fn each_reverse(s: &str, it: &fn(u8) -> bool) {
eachi_reverse(s, |_i, b| it(b) )
}
/// Iterate over the bytes in a string in reverse, with indices
#[inline(always)]
pub pure fn eachi_reverse(s: &str, it: &fn(uint, u8) -> bool) {
pub fn eachi_reverse(s: &str, it: &fn(uint, u8) -> bool) {
let mut pos = s.len();
while pos > 0 {
pos -= 1;
@@ -999,13 +999,13 @@ impl Equiv<~str> for &'self str {
/// Iterates over the chars in a string
#[inline(always)]
pub pure fn each_char(s: &str, it: &fn(char) -> bool) {
pub fn each_char(s: &str, it: &fn(char) -> bool) {
each_chari(s, |_i, c| it(c))
}
/// Iterates over the chars in a string, with indices
#[inline(always)]
pub pure fn each_chari(s: &str, it: &fn(uint, char) -> bool) {
pub fn each_chari(s: &str, it: &fn(uint, char) -> bool) {
let mut pos = 0;
let mut ch_pos = 0u;
let len = s.len();
@@ -1019,7 +1019,7 @@ impl Equiv<~str> for &'self str {
/// Iterates over the chars in a string in reverse
#[inline(always)]
pub pure fn each_char_reverse(s: &str, it: &fn(char) -> bool) {
pub fn each_char_reverse(s: &str, it: &fn(char) -> bool) {
let mut pos = 0;
let len = s.char_len();
while pos > 0 {
@@ -1031,7 +1031,7 @@ impl Equiv<~str> for &'self str {
// Iterates over the chars in a string in reverse, with indices
#[inline(always)]
pub pure fn each_chari_reverse(s: &str, it: &fn(uint, char) -> bool) {
pub fn each_chari_reverse(s: &str, it: &fn(uint, char) -> bool) {
let mut ch_pos = s.char_len();
for s.each_char_reverse |ch| {
ch_pos -= 1;
@@ -1040,7 +1040,7 @@ impl Equiv<~str> for &'self str {
}
/// Apply a function to each substring after splitting by character
pub pure fn split_char_each(ss: &str, cc: char, ff: &fn(v: &str) -> bool) {
pub fn split_char_each(ss: &str, cc: char, ff: &fn(v: &str) -> bool) {
vec::each(split_char(ss, cc), |s| ff(*s))
}
@@ -1048,20 +1048,20 @@ impl Equiv<~str> for &'self str {
* Apply a function to each substring after splitting by character, up to
* `count` times
*/
pub pure fn splitn_char_each(ss: &str, sep: char, count: uint,
pub fn splitn_char_each(ss: &str, sep: char, count: uint,
ff: &fn(v: &str) -> bool) {
vec::each(splitn_char(ss, sep, count), |s| ff(*s))
}
/// Apply a function to each word
pub pure fn words_each(ss: &str, ff: &fn(v: &str) -> bool) {
pub fn words_each(ss: &str, ff: &fn(v: &str) -> bool) {
vec::each(words(ss), |s| ff(*s))
}
/**
* Apply a function to each line (by '\n')
*/
pub pure fn lines_each(ss: &str, ff: &fn(v: &str) -> bool) {
pub fn lines_each(ss: &str, ff: &fn(v: &str) -> bool) {
vec::each(lines(ss), |s| ff(*s))
}
@@ -1082,7 +1082,7 @@ impl Equiv<~str> for &'self str {
* An `option` containing the byte index of the first matching character
* or `none` if there is no match
*/
pub pure fn find_char(s: &str, c: char) -> Option<uint> {
pub fn find_char(s: &str, c: char) -> Option<uint> {
find_char_between(s, c, 0u, len(s))
}
@@ -1106,7 +1106,7 @@ impl Equiv<~str> for &'self str {
* `start` must be less than or equal to `len(s)`. `start` must be the
* index of a character boundary, as defined by `is_char_boundary`.
*/
pub pure fn find_char_from(s: &str, c: char, start: uint) -> Option<uint> {
pub fn find_char_from(s: &str, c: char, start: uint) -> Option<uint> {
find_char_between(s, c, start, len(s))
}
@@ -1131,7 +1131,7 @@ impl Equiv<~str> for &'self str {
* or equal to `len(s)`. `start` must be the index of a character boundary,
* as defined by `is_char_boundary`.
*/
pub pure fn find_char_between(s: &str, c: char, start: uint, end: uint)
pub fn find_char_between(s: &str, c: char, start: uint, end: uint)
-> Option<uint> {
if c < 128u as char {
fail_unless!(start <= end);
@@ -1161,7 +1161,7 @@ impl Equiv<~str> for &'self str {
* An `option` containing the byte index of the last matching character
* or `none` if there is no match
*/
pub pure fn rfind_char(s: &str, c: char) -> Option<uint> {
pub fn rfind_char(s: &str, c: char) -> Option<uint> {
rfind_char_between(s, c, len(s), 0u)
}
@@ -1185,7 +1185,7 @@ impl Equiv<~str> for &'self str {
* `start` must be less than or equal to `len(s)`. `start` must be
* the index of a character boundary, as defined by `is_char_boundary`.
*/
pub pure fn rfind_char_from(s: &str, c: char, start: uint) -> Option<uint> {
pub fn rfind_char_from(s: &str, c: char, start: uint) -> Option<uint> {
rfind_char_between(s, c, start, 0u)
}
@@ -1210,7 +1210,7 @@ impl Equiv<~str> for &'self str {
* or equal to `len(s)`. `start` must be the index of a character boundary,
* as defined by `is_char_boundary`.
*/
pub pure fn rfind_char_between(s: &str, c: char, start: uint, end: uint)
pub fn rfind_char_between(s: &str, c: char, start: uint, end: uint)
-> Option<uint> {
if c < 128u as char {
fail_unless!(start >= end);
@@ -1241,7 +1241,7 @@ impl Equiv<~str> for &'self str {
* An `option` containing the byte index of the first matching character
* or `none` if there is no match
*/
pub pure fn find(s: &str, f: &fn(char) -> bool) -> Option<uint> {
pub fn find(s: &str, f: &fn(char) -> bool) -> Option<uint> {
find_between(s, 0u, len(s), f)
}
@@ -1265,7 +1265,7 @@ impl Equiv<~str> for &'self str {
* `start` must be less than or equal to `len(s)`. `start` must be the
* index of a character boundary, as defined by `is_char_boundary`.
*/
pub pure fn find_from(s: &str, start: uint, f: &fn(char)
pub fn find_from(s: &str, start: uint, f: &fn(char)
-> bool) -> Option<uint> {
find_between(s, start, len(s), f)
}
@@ -1292,7 +1292,7 @@ impl Equiv<~str> for &'self str {
* or equal to `len(s)`. `start` must be the index of a character
* boundary, as defined by `is_char_boundary`.
*/
pub pure fn find_between(s: &str,
pub fn find_between(s: &str,
start: uint,
end: uint,
f: &fn(char) -> bool)
@@ -1323,7 +1323,7 @@ impl Equiv<~str> for &'self str {
* An option containing the byte index of the last matching character
* or `none` if there is no match
*/
pub pure fn rfind(s: &str, f: &fn(char) -> bool) -> Option<uint> {
pub fn rfind(s: &str, f: &fn(char) -> bool) -> Option<uint> {
rfind_between(s, len(s), 0u, f)
}
@@ -1347,7 +1347,7 @@ impl Equiv<~str> for &'self str {
* `start` must be less than or equal to `len(s)', `start` must be the
* index of a character boundary, as defined by `is_char_boundary`
*/
pub pure fn rfind_from(s: &str, start: uint, f: &fn(char) -> bool)
pub fn rfind_from(s: &str, start: uint, f: &fn(char) -> bool)
-> Option<uint> {
rfind_between(s, start, 0u, f)
}
@@ -1374,7 +1374,7 @@ impl Equiv<~str> for &'self str {
* than or equal to `len(s)`. `start` must be the index of a character
* boundary, as defined by `is_char_boundary`
*/
pub pure fn rfind_between(s: &str, start: uint, end: uint,
pub fn rfind_between(s: &str, start: uint, end: uint,
f: &fn(char) -> bool)
-> Option<uint> {
fail_unless!(start >= end);
@@ -1390,7 +1390,7 @@ impl Equiv<~str> for &'self str {
}
// Utility used by various searching functions
pure fn match_at(haystack: &'a str, needle: &'b str, at: uint) -> bool {
fn match_at(haystack: &'a str, needle: &'b str, at: uint) -> bool {
let mut i = at;
for each(needle) |c| { if haystack[i] != c { return false; } i += 1u; }
return true;
@@ -1409,7 +1409,7 @@ impl Equiv<~str> for &'self str {
* An `option` containing the byte index of the first matching substring
* or `none` if there is no match
*/
pub pure fn find_str(haystack: &'a str, needle: &'b str) -> Option<uint> {
pub fn find_str(haystack: &'a str, needle: &'b str) -> Option<uint> {
find_str_between(haystack, needle, 0u, len(haystack))
}
@@ -1432,7 +1432,7 @@ impl Equiv<~str> for &'self str {
*
* `start` must be less than or equal to `len(s)`
*/
pub pure fn find_str_from(haystack: &'a str, needle: &'b str, start: uint)
pub fn find_str_from(haystack: &'a str, needle: &'b str, start: uint)
-> Option<uint> {
find_str_between(haystack, needle, start, len(haystack))
}
@@ -1457,7 +1457,7 @@ impl Equiv<~str> for &'self str {
* `start` must be less than or equal to `end` and `end` must be less than
* or equal to `len(s)`.
*/
pub pure fn find_str_between(haystack: &'a str, needle: &'b str, start: uint,
pub fn find_str_between(haystack: &'a str, needle: &'b str, start: uint,
end:uint)
-> Option<uint> {
// See Issue #1932 for why this is a naive search
@@ -1483,7 +1483,7 @@ impl Equiv<~str> for &'self str {
* * haystack - The string to look in
* * needle - The string to look for
*/
pub pure fn contains(haystack: &'a str, needle: &'b str) -> bool {
pub fn contains(haystack: &'a str, needle: &'b str) -> bool {
find_str(haystack, needle).is_some()
}
@@ -1495,7 +1495,7 @@ impl Equiv<~str> for &'self str {
* * haystack - The string to look in
* * needle - The char to look for
*/
pub pure fn contains_char(haystack: &str, needle: char) -> bool {
pub fn contains_char(haystack: &str, needle: char) -> bool {
find_char(haystack, needle).is_some()
}
@@ -1507,7 +1507,7 @@ impl Equiv<~str> for &'self str {
* * haystack - The string to look in
* * needle - The string to look for
*/
pub pure fn starts_with(haystack: &'a str, needle: &'b str) -> bool {
pub fn starts_with(haystack: &'a str, needle: &'b str) -> bool {
let haystack_len = len(haystack), needle_len = len(needle);
if needle_len == 0u { true }
else if needle_len > haystack_len { false }
@@ -1522,7 +1522,7 @@ impl Equiv<~str> for &'self str {
* * haystack - The string to look in
* * needle - The string to look for
*/
pub pure fn ends_with(haystack: &'a str, needle: &'b str) -> bool {
pub fn ends_with(haystack: &'a str, needle: &'b str) -> bool {
let haystack_len = len(haystack), needle_len = len(needle);
if needle_len == 0u { true }
else if needle_len > haystack_len { false }
@@ -1534,21 +1534,21 @@ impl Equiv<~str> for &'self str {
*/
/// Determines if a string contains only ASCII characters
pub pure fn is_ascii(s: &str) -> bool {
pub fn is_ascii(s: &str) -> bool {
let mut i: uint = len(s);
while i > 0u { i -= 1u; if !u8::is_ascii(s[i]) { return false; } }
return true;
}
/// Returns true if the string has length 0
pub pure fn is_empty(s: &str) -> bool { len(s) == 0u }
pub fn is_empty(s: &str) -> bool { len(s) == 0u }
/**
* Returns true if the string contains only whitespace
*
* Whitespace characters are determined by `char::is_whitespace`
*/
pub pure fn is_whitespace(s: &str) -> bool {
pub fn is_whitespace(s: &str) -> bool {
return all(s, char::is_whitespace);
}
@@ -1557,24 +1557,24 @@ impl Equiv<~str> for &'self str {
*
* Alphanumeric characters are determined by `char::is_alphanumeric`
*/
pure fn is_alphanumeric(s: &str) -> bool {
fn is_alphanumeric(s: &str) -> bool {
return all(s, char::is_alphanumeric);
}
/// Returns the string length/size in bytes not counting the null terminator
pub pure fn len(s: &str) -> uint {
pub fn len(s: &str) -> uint {
do as_buf(s) |_p, n| { n - 1u }
}
/// Returns the number of characters that a string holds
pub pure fn char_len(s: &str) -> uint { count_chars(s, 0u, len(s)) }
pub fn char_len(s: &str) -> uint { count_chars(s, 0u, len(s)) }
/*
Section: Misc
*/
/// Determines if a vector of bytes contains valid UTF-8
pub pure fn is_utf8(v: &[const u8]) -> bool {
pub fn is_utf8(v: &[const u8]) -> bool {
let mut i = 0u;
let total = vec::len::<u8>(v);
while i < total {
@@ -1592,7 +1592,7 @@ impl Equiv<~str> for &'self str {
}
/// Determines if a vector of `u16` contains valid UTF-16
pub pure fn is_utf16(v: &[u16]) -> bool {
pub fn is_utf16(v: &[u16]) -> bool {
let len = vec::len(v);
let mut i = 0u;
while (i < len) {
@@ -1613,7 +1613,7 @@ impl Equiv<~str> for &'self str {
}
/// Converts to a vector of `u16` encoded as UTF-16
pub pure fn to_utf16(s: &str) -> ~[u16] {
pub fn to_utf16(s: &str) -> ~[u16] {
let mut u = ~[];
for s.each_char |ch| {
// Arithmetic with u32 literals is easier on the eyes than chars.
@@ -1638,7 +1638,7 @@ impl Equiv<~str> for &'self str {
u
}
pub pure fn utf16_chars(v: &[u16], f: &fn(char)) {
pub fn utf16_chars(v: &[u16], f: &fn(char)) {
let len = vec::len(v);
let mut i = 0u;
while (i < len && v[i] != 0u16) {
@@ -1663,7 +1663,7 @@ impl Equiv<~str> for &'self str {
}
pub pure fn from_utf16(v: &[u16]) -> ~str {
pub fn from_utf16(v: &[u16]) -> ~str {
let mut buf = ~"";
unsafe {
reserve(&mut buf, vec::len(v));
@@ -1672,7 +1672,7 @@ impl Equiv<~str> for &'self str {
buf
}
pub pure fn with_capacity(capacity: uint) -> ~str {
pub fn with_capacity(capacity: uint) -> ~str {
let mut buf = ~"";
unsafe { reserve(&mut buf, capacity); }
buf
@@ -1691,7 +1691,7 @@ impl Equiv<~str> for &'self str {
*
* The number of Unicode characters in `s` between the given indices.
*/
pub pure fn count_chars(s: &str, start: uint, end: uint) -> uint {
pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
fail_unless!(is_char_boundary(s, start));
fail_unless!(is_char_boundary(s, end));
let mut i = start, len = 0u;
@@ -1704,7 +1704,7 @@ impl Equiv<~str> for &'self str {
}
/// Counts the number of bytes taken by the `n` in `s` starting from `start`.
pub pure fn count_bytes(s: &'b str, start: uint, n: uint) -> uint {
pub fn count_bytes(s: &'b str, start: uint, n: uint) -> uint {
fail_unless!(is_char_boundary(s, start));
let mut end = start, cnt = n;
let l = len(s);
@@ -1718,7 +1718,7 @@ impl Equiv<~str> for &'self str {
}
/// Given a first byte, determine how many bytes are in this UTF-8 character
pub pure fn utf8_char_width(b: u8) -> uint {
pub fn utf8_char_width(b: u8) -> uint {
let byte: uint = b as uint;
if byte < 128u { return 1u; }
// Not a valid start byte
@@ -1734,7 +1734,7 @@ impl Equiv<~str> for &'self str {
* Returns false if the index points into the middle of a multi-byte
* character sequence.
*/
pub pure fn is_char_boundary(s: &str, index: uint) -> bool {
pub fn is_char_boundary(s: &str, index: uint) -> bool {
if index == len(s) { return true; }
let b = s[index];
return b < 128u8 || b >= 192u8;
@@ -1789,7 +1789,7 @@ impl Equiv<~str> for &'self str {
* If `i` is greater than or equal to the length of the string.
* If `i` is not the index of the beginning of a valid UTF-8 character.
*/
pub pure fn char_range_at(s: &str, i: uint) -> CharRange {
pub fn char_range_at(s: &str, i: uint) -> CharRange {
let b0 = s[i];
let w = utf8_char_width(b0);
fail_unless!((w != 0u));
@@ -1812,7 +1812,7 @@ impl Equiv<~str> for &'self str {
}
/// Plucks the `n`th character from the beginning of a string
pub pure fn char_at(s: &str, i: uint) -> char {
pub fn char_at(s: &str, i: uint) -> char {
return char_range_at(s, i).ch;
}
@@ -1826,7 +1826,7 @@ pub struct CharRange {
*
* This function can be used to iterate over a unicode string in reverse.
*/
pure fn char_range_at_reverse(ss: &str, start: uint) -> CharRange {
fn char_range_at_reverse(ss: &str, start: uint) -> CharRange {
let mut prev = start;
// while there is a previous byte == 10......
@@ -1842,7 +1842,7 @@ pub struct CharRange {
}
/// Plucks the `n`th character from the end of a string
pub pure fn char_at_reverse(s: &str, i: uint) -> char {
pub fn char_at_reverse(s: &str, i: uint) -> char {
char_range_at_reverse(s, i).ch
}
@@ -1868,7 +1868,7 @@ pub struct CharRange {
* `true` If execution proceeded correctly, `false` if it was interrupted,
* that is if `it` returned `false` at any point.
*/
pub pure fn all_between(s: &str, start: uint, end: uint,
pub fn all_between(s: &str, start: uint, end: uint,
it: &fn(char) -> bool) -> bool {
fail_unless!(is_char_boundary(s, start));
let mut i = start;
@@ -1901,7 +1901,7 @@ pub struct CharRange {
*
* `true` if `it` returns `true` for any character
*/
pub pure fn any_between(s: &str, start: uint, end: uint,
pub fn any_between(s: &str, start: uint, end: uint,
it: &fn(char) -> bool) -> bool {
!all_between(s, start, end, |c| !it(c))
}
@@ -1940,7 +1940,7 @@ pub struct CharRange {
* let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) };
* ~~~
*/
pub pure fn as_bytes<T>(s: &const ~str, f: &fn(&~[u8]) -> T) -> T {
pub fn as_bytes<T>(s: &const ~str, f: &fn(&~[u8]) -> T) -> T {
unsafe {
let v: *~[u8] = cast::transmute(copy s);
f(&*v)
@@ -1952,7 +1952,7 @@ pub struct CharRange {
*
* The byte slice does not include the null terminator.
*/
pub pure fn as_bytes_slice(s: &'a str) -> &'a [u8] {
pub fn as_bytes_slice(s: &'a str) -> &'a [u8] {
unsafe {
let (ptr, len): (*u8, uint) = ::cast::reinterpret_cast(&s);
let outgoing_tuple: (*u8, uint) = (ptr, len - 1);
@@ -1975,7 +1975,7 @@ pub struct CharRange {
* let s = str::as_c_str("PATH", { |path| libc::getenv(path) });
* ~~~
*/
pub pure fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
pub fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
do as_buf(s) |buf, len| {
// NB: len includes the trailing null.
fail_unless!(len > 0);
@@ -1997,7 +1997,7 @@ pub struct CharRange {
* to full strings, or suffixes of them.
*/
#[inline(always)]
pub pure fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
unsafe {
let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::addr_of(&s));
let (buf,len) = *v;
@@ -2056,7 +2056,7 @@ pub fn reserve_at_least(s: &mut ~str, n: uint) {
* Returns the number of single-byte characters the string can hold without
* reallocating
*/
pub pure fn capacity(s: &const ~str) -> uint {
pub fn capacity(s: &const ~str) -> uint {
do as_bytes(s) |buf| {
let vcap = vec::capacity(buf);
fail_unless!(vcap > 0u);
@@ -2065,7 +2065,7 @@ pub fn reserve_at_least(s: &mut ~str, n: uint) {
}
/// Escape each char in `s` with char::escape_default.
pub pure fn escape_default(s: &str) -> ~str {
pub fn escape_default(s: &str) -> ~str {
let mut out: ~str = ~"";
unsafe {
reserve_at_least(&mut out, str::len(s));
@@ -2077,7 +2077,7 @@ pub fn reserve_at_least(s: &mut ~str, n: uint) {
}
/// Escape each char in `s` with char::escape_unicode.
pub pure fn escape_unicode(s: &str) -> ~str {
pub fn escape_unicode(s: &str) -> ~str {
let mut out: ~str = ~"";
unsafe {
reserve_at_least(&mut out, str::len(s));
@@ -2263,7 +2263,7 @@ pub mod traits {
impl Add<&'self str,~str> for ~str {
#[inline(always)]
pure fn add(&self, rhs: & &'self str) -> ~str {
fn add(&self, rhs: & &'self str) -> ~str {
append(copy *self, (*rhs))
}
}
@@ -2273,44 +2273,44 @@ impl Add<&'self str,~str> for ~str {
pub mod traits {}
pub trait StrSlice {
pure fn all(&self, it: &fn(char) -> bool) -> bool;
pure fn any(&self, it: &fn(char) -> bool) -> bool;
pure fn contains(&self, needle: &'a str) -> bool;
pure fn contains_char(&self, needle: char) -> bool;
pure fn each(&self, it: &fn(u8) -> bool);
pure fn eachi(&self, it: &fn(uint, u8) -> bool);
pure fn each_reverse(&self, it: &fn(u8) -> bool);
pure fn eachi_reverse(&self, it: &fn(uint, u8) -> bool);
pure fn each_char(&self, it: &fn(char) -> bool);
pure fn each_chari(&self, it: &fn(uint, char) -> bool);
pure fn each_char_reverse(&self, it: &fn(char) -> bool);
pure fn each_chari_reverse(&self, it: &fn(uint, char) -> bool);
pure fn ends_with(&self, needle: &str) -> bool;
pure fn is_empty(&self) -> bool;
pure fn is_whitespace(&self) -> bool;
pure fn is_alphanumeric(&self) -> bool;
pure fn len(&self) -> uint;
pure fn char_len(&self) -> uint;
pure fn slice(&self, begin: uint, end: uint) -> &'self str;
pure fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str];
pure fn split_char(&self, sep: char) -> ~[~str];
pure fn split_str(&self, sep: &'a str) -> ~[~str];
pure fn starts_with(&self, needle: &'a str) -> bool;
pure fn substr(&self, begin: uint, n: uint) -> &'self str;
pure fn to_lower(&self) -> ~str;
pure fn to_upper(&self) -> ~str;
pure fn escape_default(&self) -> ~str;
pure fn escape_unicode(&self) -> ~str;
pure fn trim(&self) -> &'self str;
pure fn trim_left(&self) -> &'self str;
pure fn trim_right(&self) -> &'self str;
pure fn trim_chars(&self, chars_to_trim: &[char]) -> &'self str;
pure fn trim_left_chars(&self, chars_to_trim: &[char]) -> &'self str;
pure fn trim_right_chars(&self, chars_to_trim: &[char]) -> &'self str;
pure fn to_owned(&self) -> ~str;
pure fn to_managed(&self) -> @str;
pure fn char_at(&self, i: uint) -> char;
pure fn char_at_reverse(&self, i: uint) -> char;
fn all(&self, it: &fn(char) -> bool) -> bool;
fn any(&self, it: &fn(char) -> bool) -> bool;
fn contains(&self, needle: &'a str) -> bool;
fn contains_char(&self, needle: char) -> bool;
fn each(&self, it: &fn(u8) -> bool);
fn eachi(&self, it: &fn(uint, u8) -> bool);
fn each_reverse(&self, it: &fn(u8) -> bool);
fn eachi_reverse(&self, it: &fn(uint, u8) -> bool);
fn each_char(&self, it: &fn(char) -> bool);
fn each_chari(&self, it: &fn(uint, char) -> bool);
fn each_char_reverse(&self, it: &fn(char) -> bool);
fn each_chari_reverse(&self, it: &fn(uint, char) -> bool);
fn ends_with(&self, needle: &str) -> bool;
fn is_empty(&self) -> bool;
fn is_whitespace(&self) -> bool;
fn is_alphanumeric(&self) -> bool;
fn len(&self) -> uint;
fn char_len(&self) -> uint;
fn slice(&self, begin: uint, end: uint) -> &'self str;
fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str];
fn split_char(&self, sep: char) -> ~[~str];
fn split_str(&self, sep: &'a str) -> ~[~str];
fn starts_with(&self, needle: &'a str) -> bool;
fn substr(&self, begin: uint, n: uint) -> &'self str;
fn to_lower(&self) -> ~str;
fn to_upper(&self) -> ~str;
fn escape_default(&self) -> ~str;
fn escape_unicode(&self) -> ~str;
fn trim(&self) -> &'self str;
fn trim_left(&self) -> &'self str;
fn trim_right(&self) -> &'self str;
fn trim_chars(&self, chars_to_trim: &[char]) -> &'self str;
fn trim_left_chars(&self, chars_to_trim: &[char]) -> &'self str;
fn trim_right_chars(&self, chars_to_trim: &[char]) -> &'self str;
fn to_owned(&self) -> ~str;
fn to_managed(&self) -> @str;
fn char_at(&self, i: uint) -> char;
fn char_at_reverse(&self, i: uint) -> char;
fn to_bytes(&self) -> ~[u8];
}
@@ -2321,86 +2321,86 @@ impl StrSlice for &'self str {
* contains no characters
*/
#[inline]
pure fn all(&self, it: &fn(char) -> bool) -> bool { all(*self, it) }
fn all(&self, it: &fn(char) -> bool) -> bool { all(*self, it) }
/**
* Return true if a predicate matches any character (and false if it
* matches none or there are no characters)
*/
#[inline]
pure fn any(&self, it: &fn(char) -> bool) -> bool { any(*self, it) }
fn any(&self, it: &fn(char) -> bool) -> bool { any(*self, it) }
/// Returns true if one string contains another
#[inline]
pure fn contains(&self, needle: &'a str) -> bool {
fn contains(&self, needle: &'a str) -> bool {
contains(*self, needle)
}
/// Returns true if a string contains a char
#[inline]
pure fn contains_char(&self, needle: char) -> bool {
fn contains_char(&self, needle: char) -> bool {
contains_char(*self, needle)
}
/// Iterate over the bytes in a string
#[inline]
pure fn each(&self, it: &fn(u8) -> bool) { each(*self, it) }
fn each(&self, it: &fn(u8) -> bool) { each(*self, it) }
/// Iterate over the bytes in a string, with indices
#[inline]
pure fn eachi(&self, it: &fn(uint, u8) -> bool) { eachi(*self, it) }
fn eachi(&self, it: &fn(uint, u8) -> bool) { eachi(*self, it) }
/// Iterate over the bytes in a string
#[inline]
pure fn each_reverse(&self, it: &fn(u8) -> bool) {
fn each_reverse(&self, it: &fn(u8) -> bool) {
each_reverse(*self, it)
}
/// Iterate over the bytes in a string, with indices
#[inline]
pure fn eachi_reverse(&self, it: &fn(uint, u8) -> bool) {
fn eachi_reverse(&self, it: &fn(uint, u8) -> bool) {
eachi_reverse(*self, it)
}
/// Iterate over the chars in a string
#[inline]
pure fn each_char(&self, it: &fn(char) -> bool) { each_char(*self, it) }
fn each_char(&self, it: &fn(char) -> bool) { each_char(*self, it) }
/// Iterate over the chars in a string, with indices
#[inline]
pure fn each_chari(&self, it: &fn(uint, char) -> bool) {
fn each_chari(&self, it: &fn(uint, char) -> bool) {
each_chari(*self, it)
}
/// Iterate over the chars in a string in reverse
#[inline]
pure fn each_char_reverse(&self, it: &fn(char) -> bool) {
fn each_char_reverse(&self, it: &fn(char) -> bool) {
each_char_reverse(*self, it)
}
/// Iterate over the chars in a string in reverse, with indices from the
/// end
#[inline]
pure fn each_chari_reverse(&self, it: &fn(uint, char) -> bool) {
fn each_chari_reverse(&self, it: &fn(uint, char) -> bool) {
each_chari_reverse(*self, it)
}
/// Returns true if one string ends with another
#[inline]
pure fn ends_with(&self, needle: &str) -> bool {
fn ends_with(&self, needle: &str) -> bool {
ends_with(*self, needle)
}
/// Returns true if the string has length 0
#[inline]
pure fn is_empty(&self) -> bool { is_empty(*self) }
fn is_empty(&self) -> bool { is_empty(*self) }
/**
* Returns true if the string contains only whitespace
*
* Whitespace characters are determined by `char::is_whitespace`
*/
#[inline]
pure fn is_whitespace(&self) -> bool { is_whitespace(*self) }
fn is_whitespace(&self) -> bool { is_whitespace(*self) }
/**
* Returns true if the string contains only alphanumerics
*
* Alphanumeric characters are determined by `char::is_alphanumeric`
*/
#[inline]
pure fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) }
fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) }
/// Returns the size in bytes not counting the null terminator
#[inline]
pure fn len(&self) -> uint { len(*self) }
fn len(&self) -> uint { len(*self) }
/// Returns the number of characters that a string holds
#[inline]
pure fn char_len(&self) -> uint { char_len(*self) }
fn char_len(&self) -> uint { char_len(*self) }
/**
* Returns a slice of the given string from the byte range
* [`begin`..`end`)
@@ -2409,28 +2409,28 @@ impl StrSlice for &'self str {
* beyond the last character of the string
*/
#[inline]
pure fn slice(&self, begin: uint, end: uint) -> &'self str {
fn slice(&self, begin: uint, end: uint) -> &'self str {
slice(*self, begin, end)
}
/// Splits a string into substrings using a character function
#[inline]
pure fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str] {
fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str] {
split(*self, sepfn)
}
/**
* Splits a string into substrings at each occurrence of a given character
*/
#[inline]
pure fn split_char(&self, sep: char) -> ~[~str] { split_char(*self, sep) }
fn split_char(&self, sep: char) -> ~[~str] { split_char(*self, sep) }
/**
* Splits a string into a vector of the substrings separated by a given
* string
*/
#[inline]
pure fn split_str(&self, sep: &'a str) -> ~[~str] { split_str(*self, sep) }
fn split_str(&self, sep: &'a str) -> ~[~str] { split_str(*self, sep) }
/// Returns true if one string starts with another
#[inline]
pure fn starts_with(&self, needle: &'a str) -> bool {
fn starts_with(&self, needle: &'a str) -> bool {
starts_with(*self, needle)
}
/**
@@ -2440,51 +2440,51 @@ impl StrSlice for &'self str {
* `begin`.
*/
#[inline]
pure fn substr(&self, begin: uint, n: uint) -> &'self str {
fn substr(&self, begin: uint, n: uint) -> &'self str {
substr(*self, begin, n)
}
/// Convert a string to lowercase
#[inline]
pure fn to_lower(&self) -> ~str { to_lower(*self) }
fn to_lower(&self) -> ~str { to_lower(*self) }
/// Convert a string to uppercase
#[inline]
pure fn to_upper(&self) -> ~str { to_upper(*self) }
fn to_upper(&self) -> ~str { to_upper(*self) }
/// Escape each char in `s` with char::escape_default.
#[inline]
pure fn escape_default(&self) -> ~str { escape_default(*self) }
fn escape_default(&self) -> ~str { escape_default(*self) }
/// Escape each char in `s` with char::escape_unicode.
#[inline]
pure fn escape_unicode(&self) -> ~str { escape_unicode(*self) }
fn escape_unicode(&self) -> ~str { escape_unicode(*self) }
/// Returns a string with leading and trailing whitespace removed
#[inline]
pure fn trim(&self) -> &'self str { trim(*self) }
fn trim(&self) -> &'self str { trim(*self) }
/// Returns a string with leading whitespace removed
#[inline]
pure fn trim_left(&self) -> &'self str { trim_left(*self) }
fn trim_left(&self) -> &'self str { trim_left(*self) }
/// Returns a string with trailing whitespace removed
#[inline]
pure fn trim_right(&self) -> &'self str { trim_right(*self) }
fn trim_right(&self) -> &'self str { trim_right(*self) }
#[inline]
pure fn trim_chars(&self, chars_to_trim: &[char]) -> &'self str {
fn trim_chars(&self, chars_to_trim: &[char]) -> &'self str {
trim_chars(*self, chars_to_trim)
}
#[inline]
pure fn trim_left_chars(&self, chars_to_trim: &[char]) -> &'self str {
fn trim_left_chars(&self, chars_to_trim: &[char]) -> &'self str {
trim_left_chars(*self, chars_to_trim)
}
#[inline]
pure fn trim_right_chars(&self, chars_to_trim: &[char]) -> &'self str {
fn trim_right_chars(&self, chars_to_trim: &[char]) -> &'self str {
trim_right_chars(*self, chars_to_trim)
}
#[inline]
pure fn to_owned(&self) -> ~str { from_slice(*self) }
fn to_owned(&self) -> ~str { from_slice(*self) }
#[inline]
pure fn to_managed(&self) -> @str {
fn to_managed(&self) -> @str {
let v = at_vec::from_fn(self.len() + 1, |i| {
if i == self.len() { 0 } else { self[i] }
});
@@ -2492,10 +2492,10 @@ impl StrSlice for &'self str {
}
#[inline]
pure fn char_at(&self, i: uint) -> char { char_at(*self, i) }
fn char_at(&self, i: uint) -> char { char_at(*self, i) }
#[inline]
pure fn char_at_reverse(&self, i: uint) -> char {
fn char_at_reverse(&self, i: uint) -> char {
char_at_reverse(*self, i)
}
+13 -13
View File
@@ -60,15 +60,15 @@ unsafe fn rust_upcall_fail(expr: *c_char,
/// Compares contents of two pointers using the default method.
/// Equivalent to `*x1 == *x2`. Useful for hashtables.
pub pure fn shape_eq<T:Eq>(x1: &T, x2: &T) -> bool {
pub fn shape_eq<T:Eq>(x1: &T, x2: &T) -> bool {
*x1 == *x2
}
pub pure fn shape_lt<T:Ord>(x1: &T, x2: &T) -> bool {
pub fn shape_lt<T:Ord>(x1: &T, x2: &T) -> bool {
*x1 < *x2
}
pub pure fn shape_le<T:Ord>(x1: &T, x2: &T) -> bool {
pub fn shape_le<T:Ord>(x1: &T, x2: &T) -> bool {
*x1 <= *x2
}
@@ -79,13 +79,13 @@ unsafe fn rust_upcall_fail(expr: *c_char,
* performing dark magick.
*/
#[inline(always)]
pub pure fn get_type_desc<T>() -> *TypeDesc {
pub fn get_type_desc<T>() -> *TypeDesc {
unsafe { rusti::get_tydesc::<T>() as *TypeDesc }
}
/// Returns the size of a type
#[inline(always)]
pub pure fn size_of<T>() -> uint {
pub fn size_of<T>() -> uint {
unsafe { rusti::size_of::<T>() }
}
@@ -95,7 +95,7 @@ unsafe fn rust_upcall_fail(expr: *c_char,
* Useful for building structures containing variable-length arrays.
*/
#[inline(always)]
pub pure fn nonzero_size_of<T>() -> uint {
pub fn nonzero_size_of<T>() -> uint {
let s = size_of::<T>();
if s == 0 { 1 } else { s }
}
@@ -107,26 +107,26 @@ unsafe fn rust_upcall_fail(expr: *c_char,
* than the preferred alignment.
*/
#[inline(always)]
pub pure fn min_align_of<T>() -> uint {
pub fn min_align_of<T>() -> uint {
unsafe { rusti::min_align_of::<T>() }
}
/// Returns the preferred alignment of a type
#[inline(always)]
pub pure fn pref_align_of<T>() -> uint {
pub fn pref_align_of<T>() -> uint {
unsafe { rusti::pref_align_of::<T>() }
}
/// Returns the refcount of a shared box (as just before calling this)
#[inline(always)]
pub pure fn refcount<T>(t: @T) -> uint {
pub fn refcount<T>(t: @T) -> uint {
unsafe {
let ref_ptr: *uint = cast::reinterpret_cast(&t);
*ref_ptr - 1
}
}
pub pure fn log_str<T>(t: &T) -> ~str {
pub fn log_str<T>(t: &T) -> ~str {
unsafe {
do io::with_str_writer |wr| {
repr::write_repr(wr, t)
@@ -135,7 +135,7 @@ unsafe fn rust_upcall_fail(expr: *c_char,
}
/** Initiate task failure */
pub pure fn begin_unwind(msg: ~str, file: ~str, line: uint) -> ! {
pub fn begin_unwind(msg: ~str, file: ~str, line: uint) -> ! {
do str::as_buf(msg) |msg_buf, _msg_len| {
do str::as_buf(file) |file_buf, _file_len| {
unsafe {
@@ -148,7 +148,7 @@ unsafe fn rust_upcall_fail(expr: *c_char,
}
// FIXME #4427: Temporary until rt::rt_fail_ goes away
pub pure fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
unsafe {
gc::cleanup_stack_for_failure();
rustrt::rust_upcall_fail(msg, file, line);
@@ -156,7 +156,7 @@ unsafe fn rust_upcall_fail(expr: *c_char,
}
}
pub pure fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
unsafe {
let (msg, file) = (msg.to_owned(), file.to_owned());
begin_unwind(~"assertion failed: " + msg, file, line)
+2 -2
View File
@@ -24,14 +24,14 @@ pub trait LocalData { }
impl<T:Durable> LocalData for @T { }
impl Eq for @LocalData {
pure fn eq(&self, other: &@LocalData) -> bool {
fn eq(&self, other: &@LocalData) -> bool {
unsafe {
let ptr_a: (uint, uint) = cast::reinterpret_cast(&(*self));
let ptr_b: (uint, uint) = cast::reinterpret_cast(other);
return ptr_a == ptr_b;
}
}
pure fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) }
fn ne(&self, other: &@LocalData) -> bool { !(*self).eq(other) }
}
// If TLS is used heavily in future, this could be made more efficient with a
+2 -2
View File
@@ -78,13 +78,13 @@ pub enum TaskResult {
}
impl Eq for TaskResult {
pure fn eq(&self, other: &TaskResult) -> bool {
fn eq(&self, other: &TaskResult) -> bool {
match ((*self), (*other)) {
(Success, Success) | (Failure, Failure) => true,
(Success, _) | (Failure, _) => false
}
}
pure fn ne(&self, other: &TaskResult) -> bool { !(*self).eq(other) }
fn ne(&self, other: &TaskResult) -> bool { !(*self).eq(other) }
}
/// Scheduler modes
+1 -1
View File
@@ -126,7 +126,7 @@ struct TaskGroupData {
type TaskGroupInner = &'self mut Option<TaskGroupData>;
// A taskgroup is 'dead' when nothing can cause it to fail; only members can.
pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
(&const tg.members).is_empty()
}
+34 -34
View File
@@ -43,12 +43,12 @@ pub trait IterBytes {
* left-to-right in declaration order, regardless of
* underlying memory endianness.
*/
pure fn iter_bytes(&self, lsb0: bool, f: Cb);
fn iter_bytes(&self, lsb0: bool, f: Cb);
}
impl IterBytes for bool {
#[inline(always)]
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
f([
*self as u8
]);
@@ -57,7 +57,7 @@ impl IterBytes for bool {
impl IterBytes for u8 {
#[inline(always)]
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
f([
*self
]);
@@ -66,7 +66,7 @@ impl IterBytes for u8 {
impl IterBytes for u16 {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
if lsb0 {
f([
*self as u8,
@@ -83,7 +83,7 @@ impl IterBytes for u16 {
impl IterBytes for u32 {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
if lsb0 {
f([
*self as u8,
@@ -104,7 +104,7 @@ impl IterBytes for u32 {
impl IterBytes for u64 {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
if lsb0 {
f([
*self as u8,
@@ -133,35 +133,35 @@ impl IterBytes for u64 {
impl IterBytes for i8 {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as u8).iter_bytes(lsb0, f)
}
}
impl IterBytes for i16 {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as u16).iter_bytes(lsb0, f)
}
}
impl IterBytes for i32 {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as u32).iter_bytes(lsb0, f)
}
}
impl IterBytes for i64 {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as u64).iter_bytes(lsb0, f)
}
}
impl IterBytes for char {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as u32).iter_bytes(lsb0, f)
}
}
@@ -172,7 +172,7 @@ pub mod x32 {
impl IterBytes for uint {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as u32).iter_bytes(lsb0, f)
}
}
@@ -184,7 +184,7 @@ pub mod x64 {
impl IterBytes for uint {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as u64).iter_bytes(lsb0, f)
}
}
@@ -192,14 +192,14 @@ impl IterBytes for uint {
impl IterBytes for int {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as uint).iter_bytes(lsb0, f)
}
}
impl<A:IterBytes> IterBytes for &'self [A] {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
for (*self).each |elt| {
do elt.iter_bytes(lsb0) |bytes| {
f(bytes)
@@ -210,7 +210,7 @@ impl<A:IterBytes> IterBytes for &'self [A] {
impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
match *self {
(ref a, ref b) => {
iter_bytes_2(a, b, lsb0, f);
@@ -221,7 +221,7 @@ impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) {
impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
match *self {
(ref a, ref b, ref c) => {
iter_bytes_3(a, b, c, lsb0, f);
@@ -231,25 +231,25 @@ impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) {
}
// Move this to vec, probably.
pure fn borrow<A>(a: &'x [A]) -> &'x [A] {
fn borrow<A>(a: &'x [A]) -> &'x [A] {
a
}
impl<A:IterBytes> IterBytes for ~[A] {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
borrow(*self).iter_bytes(lsb0, f)
}
}
impl<A:IterBytes> IterBytes for @[A] {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
borrow(*self).iter_bytes(lsb0, f)
}
}
pub pure fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B,
pub fn iter_bytes_2<A:IterBytes,B:IterBytes>(a: &A, b: &B,
lsb0: bool, z: Cb) {
let mut flag = true;
a.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
@@ -257,7 +257,7 @@ impl<A:IterBytes> IterBytes for @[A] {
b.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
pub pure fn iter_bytes_3<A: IterBytes,
pub fn iter_bytes_3<A: IterBytes,
B: IterBytes,
C: IterBytes>(a: &A, b: &B, c: &C,
lsb0: bool, z: Cb) {
@@ -269,7 +269,7 @@ impl<A:IterBytes> IterBytes for @[A] {
c.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
pub pure fn iter_bytes_4<A: IterBytes,
pub fn iter_bytes_4<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes>(a: &A, b: &B, c: &C,
@@ -285,7 +285,7 @@ impl<A:IterBytes> IterBytes for @[A] {
d.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
pub pure fn iter_bytes_5<A: IterBytes,
pub fn iter_bytes_5<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes,
@@ -304,7 +304,7 @@ impl<A:IterBytes> IterBytes for @[A] {
e.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
pub pure fn iter_bytes_6<A: IterBytes,
pub fn iter_bytes_6<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes,
@@ -326,7 +326,7 @@ impl<A:IterBytes> IterBytes for @[A] {
f.iter_bytes(lsb0, |bytes| {flag = z(bytes); flag});
}
pub pure fn iter_bytes_7<A: IterBytes,
pub fn iter_bytes_7<A: IterBytes,
B: IterBytes,
C: IterBytes,
D: IterBytes,
@@ -354,7 +354,7 @@ impl<A:IterBytes> IterBytes for @[A] {
impl IterBytes for &'self str {
#[inline(always)]
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
do str::byte_slice(*self) |bytes| {
f(bytes);
}
@@ -363,7 +363,7 @@ impl IterBytes for &'self str {
impl IterBytes for ~str {
#[inline(always)]
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
do str::byte_slice(*self) |bytes| {
f(bytes);
}
@@ -372,7 +372,7 @@ impl IterBytes for ~str {
impl IterBytes for @str {
#[inline(always)]
pure fn iter_bytes(&self, _lsb0: bool, f: Cb) {
fn iter_bytes(&self, _lsb0: bool, f: Cb) {
do str::byte_slice(*self) |bytes| {
f(bytes);
}
@@ -381,7 +381,7 @@ impl IterBytes for @str {
impl<A:IterBytes> IterBytes for Option<A> {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
match *self {
Some(ref a) => iter_bytes_2(&0u8, a, lsb0, f),
None => 1u8.iter_bytes(lsb0, f)
@@ -391,21 +391,21 @@ impl<A:IterBytes> IterBytes for Option<A> {
impl<A:IterBytes> IterBytes for &'self A {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(**self).iter_bytes(lsb0, f);
}
}
impl<A:IterBytes> IterBytes for @A {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(**self).iter_bytes(lsb0, f);
}
}
impl<A:IterBytes> IterBytes for ~A {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(**self).iter_bytes(lsb0, f);
}
}
@@ -414,7 +414,7 @@ impl<A:IterBytes> IterBytes for ~A {
// to the target; it just gives you the pointer-bytes.
impl<A> IterBytes for *const A {
#[inline(always)]
pure fn iter_bytes(&self, lsb0: bool, f: Cb) {
fn iter_bytes(&self, lsb0: bool, f: Cb) {
(*self as uint).iter_bytes(lsb0, f);
}
}
+8 -8
View File
@@ -17,23 +17,23 @@
use str;
pub trait ToStr {
pure fn to_str(&self) -> ~str;
fn to_str(&self) -> ~str;
}
impl ToStr for bool {
#[inline(always)]
pure fn to_str(&self) -> ~str { ::bool::to_str(*self) }
fn to_str(&self) -> ~str { ::bool::to_str(*self) }
}
impl ToStr for () {
#[inline(always)]
pure fn to_str(&self) -> ~str { ~"()" }
fn to_str(&self) -> ~str { ~"()" }
}
// FIXME #4898: impl for one-tuples
impl<A:ToStr,B:ToStr> ToStr for (A, B) {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
// FIXME(#4760): this causes an llvm assertion
//let &(ref a, ref b) = self;
match *self {
@@ -45,7 +45,7 @@ impl<A:ToStr,B:ToStr> ToStr for (A, B) {
}
impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
// FIXME(#4760): this causes an llvm assertion
//let &(ref a, ref b, ref c) = self;
match *self {
@@ -62,7 +62,7 @@ impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
impl<A:ToStr> ToStr for &'self [A] {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
unsafe {
// FIXME #4568
// Bleh -- not really unsafe
@@ -83,7 +83,7 @@ impl<A:ToStr> ToStr for &'self [A] {
impl<A:ToStr> ToStr for ~[A] {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
unsafe {
// FIXME #4568
// Bleh -- not really unsafe
@@ -104,7 +104,7 @@ impl<A:ToStr> ToStr for ~[A] {
impl<A:ToStr> ToStr for @[A] {
#[inline(always)]
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
unsafe {
// FIXME #4568
// Bleh -- not really unsafe
+23 -23
View File
@@ -32,17 +32,17 @@ pub struct TrieMap<T> {
impl<T> BaseIter<(uint, &'self T)> for TrieMap<T> {
/// Visit all key-value pairs in order
#[inline(always)]
pure fn each(&self, f: &fn(&(uint, &'self T)) -> bool) {
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) {
self.root.each(f);
}
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
/// Visit all key-value pairs in reverse order
#[inline(always)]
pure fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) {
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) {
self.root.each_reverse(f);
}
}
@@ -50,11 +50,11 @@ impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
impl<T> Container for TrieMap<T> {
/// Return the number of elements in the map
#[inline(always)]
pure fn len(&const self) -> uint { self.length }
fn len(&const self) -> uint { self.length }
/// Return true if the map contains no elements
#[inline(always)]
pure fn is_empty(&const self) -> bool { self.len() == 0 }
fn is_empty(&const self) -> bool { self.len() == 0 }
}
impl<T> Mutable for TrieMap<T> {
@@ -69,19 +69,19 @@ fn clear(&mut self) {
impl<T> Map<uint, T> for TrieMap<T> {
/// Return true if the map contains a value for the specified key
#[inline(always)]
pure fn contains_key(&self, key: &uint) -> bool {
fn contains_key(&self, key: &uint) -> bool {
self.find(key).is_some()
}
/// Visit all keys in order
#[inline(always)]
pure fn each_key(&self, f: &fn(&uint) -> bool) {
fn each_key(&self, f: &fn(&uint) -> bool) {
self.each(|&(k, _)| f(&k))
}
/// Visit all values in order
#[inline(always)]
pure fn each_value(&self, f: &fn(&T) -> bool) {
fn each_value(&self, f: &fn(&T) -> bool) {
self.each(|&(_, v)| f(v))
}
@@ -93,7 +93,7 @@ fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) {
/// Return the value corresponding to the key in the map
#[inline(hint)]
pure fn find(&self, key: &uint) -> Option<&'self T> {
fn find(&self, key: &uint) -> Option<&'self T> {
let mut node: &'self TrieNode<T> = &self.root;
let mut idx = 0;
loop {
@@ -139,19 +139,19 @@ fn remove(&mut self, key: &uint) -> bool {
pub impl<T> TrieMap<T> {
/// Create an empty TrieMap
#[inline(always)]
pure fn new() -> TrieMap<T> {
fn new() -> TrieMap<T> {
TrieMap{root: TrieNode::new(), length: 0}
}
/// Visit all keys in reverse order
#[inline(always)]
pure fn each_key_reverse(&self, f: &fn(&uint) -> bool) {
fn each_key_reverse(&self, f: &fn(&uint) -> bool) {
self.each_reverse(|&(k, _)| f(&k))
}
/// Visit all values in reverse order
#[inline(always)]
pure fn each_value_reverse(&self, f: &fn(&T) -> bool) {
fn each_value_reverse(&self, f: &fn(&T) -> bool) {
self.each_reverse(|&(_, v)| f(v))
}
}
@@ -162,13 +162,13 @@ pub struct TrieSet {
impl BaseIter<uint> for TrieSet {
/// Visit all values in order
pure fn each(&self, f: &fn(&uint) -> bool) { self.map.each_key(f) }
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn each(&self, f: &fn(&uint) -> bool) { self.map.each_key(f) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl ReverseIter<uint> for TrieSet {
/// Visit all values in reverse order
pure fn each_reverse(&self, f: &fn(&uint) -> bool) {
fn each_reverse(&self, f: &fn(&uint) -> bool) {
self.map.each_key_reverse(f)
}
}
@@ -176,11 +176,11 @@ impl ReverseIter<uint> for TrieSet {
impl Container for TrieSet {
/// Return the number of elements in the set
#[inline(always)]
pure fn len(&const self) -> uint { self.map.len() }
fn len(&const self) -> uint { self.map.len() }
/// Return true if the set contains no elements
#[inline(always)]
pure fn is_empty(&const self) -> bool { self.map.is_empty() }
fn is_empty(&const self) -> bool { self.map.is_empty() }
}
impl Mutable for TrieSet {
@@ -192,13 +192,13 @@ fn clear(&mut self) { self.map.clear() }
impl TrieSet {
/// Create an empty TrieSet
#[inline(always)]
pure fn new() -> TrieSet {
fn new() -> TrieSet {
TrieSet{map: TrieMap::new()}
}
/// Return true if the set contains a value
#[inline(always)]
pure fn contains(&self, value: &uint) -> bool {
fn contains(&self, value: &uint) -> bool {
self.map.contains_key(value)
}
@@ -220,7 +220,7 @@ struct TrieNode<T> {
impl<T> TrieNode<T> {
#[inline(always)]
pure fn new() -> TrieNode<T> {
fn new() -> TrieNode<T> {
// FIXME: #5244: [Nothing, ..SIZE] should be possible without Copy
TrieNode{count: 0,
children: [Nothing, Nothing, Nothing, Nothing,
@@ -231,7 +231,7 @@ impl<T> TrieNode<T> {
}
impl<T> TrieNode<T> {
pure fn each(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
fn each(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
for uint::range(0, self.children.len()) |idx| {
match self.children[idx] {
Internal(ref x) => if !x.each(f) { return false },
@@ -242,7 +242,7 @@ impl<T> TrieNode<T> {
true
}
pure fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
fn each_reverse(&self, f: &fn(&(uint, &'self T)) -> bool) -> bool {
for uint::range_rev(self.children.len(), 0) |idx| {
match self.children[idx - 1] {
Internal(ref x) => if !x.each_reverse(f) { return false },
@@ -269,7 +269,7 @@ fn mutate_values(&mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
// if this was done via a trait, the key could be generic
#[inline(always)]
pure fn chunk(n: uint, idx: uint) -> uint {
fn chunk(n: uint, idx: uint) -> uint {
let sh = uint::bits - (SHIFT * (idx + 1));
(n >> sh) & MASK
}
+22 -22
View File
@@ -16,30 +16,30 @@
#[cfg(notest)] use cmp::{Eq, Ord};
pub trait CopyableTuple<T, U> {
pure fn first(&self) -> T;
pure fn second(&self) -> U;
pure fn swap(&self) -> (U, T);
fn first(&self) -> T;
fn second(&self) -> U;
fn swap(&self) -> (U, T);
}
impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
/// Return the first element of self
#[inline(always)]
pure fn first(&self) -> T {
fn first(&self) -> T {
let (t, _) = *self;
return t;
}
/// Return the second element of self
#[inline(always)]
pure fn second(&self) -> U {
fn second(&self) -> U {
let (_, u) = *self;
return u;
}
/// Return the results of swapping the two elements of self
#[inline(always)]
pure fn swap(&self) -> (U, T) {
fn swap(&self) -> (U, T) {
let (t, u) = *self;
return (u, t);
}
@@ -47,19 +47,19 @@ impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
}
pub trait ImmutableTuple<T, U> {
pure fn first_ref(&self) -> &'self T;
pure fn second_ref(&self) -> &'self U;
fn first_ref(&self) -> &'self T;
fn second_ref(&self) -> &'self U;
}
impl<T, U> ImmutableTuple<T, U> for (T, U) {
#[inline(always)]
pure fn first_ref(&self) -> &'self T {
fn first_ref(&self) -> &'self T {
match *self {
(ref t, _) => t,
}
}
#[inline(always)]
pure fn second_ref(&self) -> &'self U {
fn second_ref(&self) -> &'self U {
match *self {
(_, ref u) => u,
}
@@ -117,7 +117,7 @@ fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
#[cfg(notest)]
impl<A:Eq,B:Eq> Eq for (A, B) {
#[inline(always)]
pure fn eq(&self, other: &(A, B)) -> bool {
fn eq(&self, other: &(A, B)) -> bool {
match (*self) {
(ref self_a, ref self_b) => match other {
&(ref other_a, ref other_b) => {
@@ -127,13 +127,13 @@ impl<A:Eq,B:Eq> Eq for (A, B) {
}
}
#[inline(always)]
pure fn ne(&self, other: &(A, B)) -> bool { !(*self).eq(other) }
fn ne(&self, other: &(A, B)) -> bool { !(*self).eq(other) }
}
#[cfg(notest)]
impl<A:Ord,B:Ord> Ord for (A, B) {
#[inline(always)]
pure fn lt(&self, other: &(A, B)) -> bool {
fn lt(&self, other: &(A, B)) -> bool {
match (*self) {
(ref self_a, ref self_b) => {
match (*other) {
@@ -148,17 +148,17 @@ impl<A:Ord,B:Ord> Ord for (A, B) {
}
}
#[inline(always)]
pure fn le(&self, other: &(A, B)) -> bool { !(*other).lt(&(*self)) }
fn le(&self, other: &(A, B)) -> bool { !(*other).lt(&(*self)) }
#[inline(always)]
pure fn ge(&self, other: &(A, B)) -> bool { !(*self).lt(other) }
fn ge(&self, other: &(A, B)) -> bool { !(*self).lt(other) }
#[inline(always)]
pure fn gt(&self, other: &(A, B)) -> bool { (*other).lt(&(*self)) }
fn gt(&self, other: &(A, B)) -> bool { (*other).lt(&(*self)) }
}
#[cfg(notest)]
impl<A:Eq,B:Eq,C:Eq> Eq for (A, B, C) {
#[inline(always)]
pure fn eq(&self, other: &(A, B, C)) -> bool {
fn eq(&self, other: &(A, B, C)) -> bool {
match (*self) {
(ref self_a, ref self_b, ref self_c) => match other {
&(ref other_a, ref other_b, ref other_c) => {
@@ -169,13 +169,13 @@ impl<A:Eq,B:Eq,C:Eq> Eq for (A, B, C) {
}
}
#[inline(always)]
pure fn ne(&self, other: &(A, B, C)) -> bool { !(*self).eq(other) }
fn ne(&self, other: &(A, B, C)) -> bool { !(*self).eq(other) }
}
#[cfg(notest)]
impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
#[inline(always)]
pure fn lt(&self, other: &(A, B, C)) -> bool {
fn lt(&self, other: &(A, B, C)) -> bool {
match (*self) {
(ref self_a, ref self_b, ref self_c) => {
match (*other) {
@@ -192,11 +192,11 @@ impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
}
}
#[inline(always)]
pure fn le(&self, other: &(A, B, C)) -> bool { !(*other).lt(&(*self)) }
fn le(&self, other: &(A, B, C)) -> bool { !(*other).lt(&(*self)) }
#[inline(always)]
pure fn ge(&self, other: &(A, B, C)) -> bool { !(*self).lt(other) }
fn ge(&self, other: &(A, B, C)) -> bool { !(*self).lt(other) }
#[inline(always)]
pure fn gt(&self, other: &(A, B, C)) -> bool { (*other).lt(&(*self)) }
fn gt(&self, other: &(A, B, C)) -> bool { (*other).lt(&(*self)) }
}
#[test]
+32 -32
View File
@@ -11,7 +11,7 @@
#[doc(hidden)]; // FIXME #3538
pub mod general_category {
pub pure fn Cc(c: char) -> bool {
pub fn Cc(c: char) -> bool {
return match c {
'\x00' .. '\x1f'
| '\x7f' .. '\x9f' => true,
@@ -19,7 +19,7 @@ pub mod general_category {
};
}
pub pure fn Cf(c: char) -> bool {
pub fn Cf(c: char) -> bool {
return match c {
'\xad'
| '\u0600' .. '\u0603'
@@ -38,21 +38,21 @@ pub mod general_category {
};
}
pub pure fn Co(c: char) -> bool {
pub fn Co(c: char) -> bool {
return match c {
'\ue000' .. '\uf8ff' => true,
_ => false
};
}
pub pure fn Cs(c: char) -> bool {
pub fn Cs(c: char) -> bool {
return match c {
'\ud800' .. '\udfff' => true,
_ => false
};
}
pub pure fn Ll(c: char) -> bool {
pub fn Ll(c: char) -> bool {
return match c {
'\x61' .. '\x7a'
| '\xaa'
@@ -657,7 +657,7 @@ pub mod general_category {
};
}
pub pure fn Lm(c: char) -> bool {
pub fn Lm(c: char) -> bool {
return match c {
'\u02b0' .. '\u02c1'
| '\u02c6' .. '\u02d1'
@@ -713,7 +713,7 @@ pub mod general_category {
};
}
pub pure fn Lo(c: char) -> bool {
pub fn Lo(c: char) -> bool {
return match c {
'\u01bb'
| '\u01c0' .. '\u01c3'
@@ -899,7 +899,7 @@ pub mod general_category {
};
}
pub pure fn Lt(c: char) -> bool {
pub fn Lt(c: char) -> bool {
return match c {
'\u01c5'
| '\u01c8'
@@ -916,7 +916,7 @@ pub mod general_category {
};
}
pub pure fn Lu(c: char) -> bool {
pub fn Lu(c: char) -> bool {
return match c {
'\x41' .. '\x5a'
| '\xc0' .. '\xd6'
@@ -1508,7 +1508,7 @@ pub mod general_category {
};
}
pub pure fn Mc(c: char) -> bool {
pub fn Mc(c: char) -> bool {
return match c {
'\u0903'
| '\u093b'
@@ -1619,7 +1619,7 @@ pub mod general_category {
};
}
pub pure fn Me(c: char) -> bool {
pub fn Me(c: char) -> bool {
return match c {
'\u0488' .. '\u0489'
| '\u20dd' .. '\u20e0'
@@ -1630,7 +1630,7 @@ pub mod general_category {
};
}
pub pure fn Mn(c: char) -> bool {
pub fn Mn(c: char) -> bool {
return match c {
'\u0300' .. '\u036f'
| '\u0483' .. '\u0487'
@@ -1823,7 +1823,7 @@ pub mod general_category {
};
}
pub pure fn Nd(c: char) -> bool {
pub fn Nd(c: char) -> bool {
return match c {
'\x30' .. '\x39'
| '\u0660' .. '\u0669'
@@ -1867,7 +1867,7 @@ pub mod general_category {
};
}
pub pure fn Nl(c: char) -> bool {
pub fn Nl(c: char) -> bool {
return match c {
'\u16ee' .. '\u16f0'
| '\u2160' .. '\u2182'
@@ -1886,7 +1886,7 @@ pub mod general_category {
};
}
pub pure fn No(c: char) -> bool {
pub fn No(c: char) -> bool {
return match c {
'\xb2' .. '\xb3'
| '\xb9'
@@ -1934,7 +1934,7 @@ pub mod general_category {
};
}
pub pure fn Pc(c: char) -> bool {
pub fn Pc(c: char) -> bool {
return match c {
'\x5f'
| '\u203f' .. '\u2040'
@@ -1947,7 +1947,7 @@ pub mod general_category {
};
}
pub pure fn Pd(c: char) -> bool {
pub fn Pd(c: char) -> bool {
return match c {
'\x2d'
| '\u058a'
@@ -1969,7 +1969,7 @@ pub mod general_category {
};
}
pub pure fn Pe(c: char) -> bool {
pub fn Pe(c: char) -> bool {
return match c {
'\x29'
| '\x5d'
@@ -2046,7 +2046,7 @@ pub mod general_category {
};
}
pub pure fn Pf(c: char) -> bool {
pub fn Pf(c: char) -> bool {
return match c {
'\xbb'
| '\u2019'
@@ -2063,7 +2063,7 @@ pub mod general_category {
};
}
pub pure fn Pi(c: char) -> bool {
pub fn Pi(c: char) -> bool {
return match c {
'\xab'
| '\u2018'
@@ -2081,7 +2081,7 @@ pub mod general_category {
};
}
pub pure fn Po(c: char) -> bool {
pub fn Po(c: char) -> bool {
return match c {
'\x21' .. '\x23'
| '\x25' .. '\x27'
@@ -2214,7 +2214,7 @@ pub mod general_category {
};
}
pub pure fn Ps(c: char) -> bool {
pub fn Ps(c: char) -> bool {
return match c {
'\x28'
| '\x5b'
@@ -2293,7 +2293,7 @@ pub mod general_category {
};
}
pub pure fn Sc(c: char) -> bool {
pub fn Sc(c: char) -> bool {
return match c {
'\x24'
| '\xa2' .. '\xa5'
@@ -2316,7 +2316,7 @@ pub mod general_category {
};
}
pub pure fn Sk(c: char) -> bool {
pub fn Sk(c: char) -> bool {
return match c {
'\x5e'
| '\x60'
@@ -2350,7 +2350,7 @@ pub mod general_category {
};
}
pub pure fn Sm(c: char) -> bool {
pub fn Sm(c: char) -> bool {
return match c {
'\x2b'
| '\x3c' .. '\x3e'
@@ -2421,7 +2421,7 @@ pub mod general_category {
};
}
pub pure fn So(c: char) -> bool {
pub fn So(c: char) -> bool {
return match c {
'\xa6' .. '\xa7'
| '\xa9'
@@ -2540,21 +2540,21 @@ pub mod general_category {
};
}
pub pure fn Zl(c: char) -> bool {
pub fn Zl(c: char) -> bool {
return match c {
'\u2028' => true,
_ => false
};
}
pub pure fn Zp(c: char) -> bool {
pub fn Zp(c: char) -> bool {
return match c {
'\u2029' => true,
_ => false
};
}
pub pure fn Zs(c: char) -> bool {
pub fn Zs(c: char) -> bool {
return match c {
'\x20'
| '\xa0'
@@ -2572,7 +2572,7 @@ pub mod general_category {
}
mod derived_property {
/// Check if a character has the alphabetic unicode property
pub pure fn Alphabetic(c: char) -> bool {
pub fn Alphabetic(c: char) -> bool {
return match c {
'\x41' .. '\x5a'
| '\x61' .. '\x7a'
@@ -3310,7 +3310,7 @@ mod derived_property {
};
}
pub pure fn XID_Continue(c: char) -> bool {
pub fn XID_Continue(c: char) -> bool {
return match c {
'\x30' .. '\x39'
| '\x41' .. '\x5a'
@@ -4181,7 +4181,7 @@ mod derived_property {
};
}
pub pure fn XID_Start(c: char) -> bool {
pub fn XID_Start(c: char) -> bool {
return match c {
'\x41' .. '\x5a'
| '\x61' .. '\x7a'
+13 -13
View File
@@ -140,7 +140,7 @@ struct Parsed<T> {
}
pub impl<T> Parsed<T> {
pure fn new(val: T, next: uint) -> Parsed<T> {
fn new(val: T, next: uint) -> Parsed<T> {
Parsed {val: val, next: next}
}
}
@@ -496,7 +496,7 @@ pub struct Conv {
ty: Ty,
}
pub pure fn conv_int(cv: Conv, i: int) -> ~str {
pub fn conv_int(cv: Conv, i: int) -> ~str {
let radix = 10;
let prec = get_int_precision(cv);
let mut s : ~str = int_to_str_prec(i, radix, prec);
@@ -509,7 +509,7 @@ pub struct Conv {
}
return unsafe { pad(cv, s, PadSigned) };
}
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
pub fn conv_uint(cv: Conv, u: uint) -> ~str {
let prec = get_int_precision(cv);
let mut rs =
match cv.ty {
@@ -521,17 +521,17 @@ pub struct Conv {
};
return unsafe { pad(cv, rs, PadUnsigned) };
}
pub pure fn conv_bool(cv: Conv, b: bool) -> ~str {
pub fn conv_bool(cv: Conv, b: bool) -> ~str {
let s = if b { ~"true" } else { ~"false" };
// run the boolean conversion through the string conversion logic,
// giving it the same rules for precision, etc.
return conv_str(cv, s);
}
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
pub fn conv_char(cv: Conv, c: char) -> ~str {
let mut s = str::from_char(c);
return unsafe { pad(cv, s, PadNozero) };
}
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
pub fn conv_str(cv: Conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
// displayed
let mut unpadded = match cv.precision {
@@ -544,7 +544,7 @@ pub struct Conv {
};
return unsafe { pad(cv, unpadded, PadNozero) };
}
pub pure fn conv_float(cv: Conv, f: float) -> ~str {
pub fn conv_float(cv: Conv, f: float) -> ~str {
let (to_str, digits) = match cv.precision {
CountIs(c) => (float::to_str_exact, c as uint),
CountImplied => (float::to_str_digits, 6u)
@@ -559,14 +559,14 @@ pub struct Conv {
}
return unsafe { pad(cv, s, PadFloat) };
}
pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
pub fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
let s = sys::log_str(v);
return conv_str(cv, s);
}
// Convert an int to string with minimum number of digits. If precision is
// 0 and num is 0 then the result is the empty string.
pub pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
pub fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
return if num < 0 {
~"-" + uint_to_str_prec(-num as uint, radix, prec)
} else { uint_to_str_prec(num as uint, radix, prec) };
@@ -575,7 +575,7 @@ pub struct Conv {
// Convert a uint to string with a minimum number of digits. If precision
// is 0 and num is 0 then the result is the empty string. Could move this
// to uint: but it doesn't seem all that useful.
pub pure fn uint_to_str_prec(num: uint, radix: uint,
pub fn uint_to_str_prec(num: uint, radix: uint,
prec: uint) -> ~str {
return if prec == 0u && num == 0u {
~""
@@ -589,7 +589,7 @@ pub struct Conv {
} else { s }
};
}
pub pure fn get_int_precision(cv: Conv) -> uint {
pub fn get_int_precision(cv: Conv) -> uint {
return match cv.precision {
CountIs(c) => c as uint,
CountImplied => 1u
@@ -619,7 +619,7 @@ pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
PadFloat => (true, true),
PadUnsigned => (true, false)
};
pure fn have_precision(cv: Conv) -> bool {
fn have_precision(cv: Conv) -> bool {
return match cv.precision { CountImplied => false, _ => true };
}
let zero_padding = {
@@ -649,7 +649,7 @@ pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
}
return padstr + s;
}
pub pure fn have_flag(flags: u32, f: u32) -> bool {
pub fn have_flag(flags: u32, f: u32) -> bool {
flags & f != 0
}
}
+2 -2
View File
@@ -18,11 +18,11 @@
/// The identity function.
#[inline(always)]
pub pure fn id<T>(x: T) -> T { x }
pub fn id<T>(x: T) -> T { x }
/// Ignores a value.
#[inline(always)]
pub pure fn ignore<T>(_x: T) { }
pub fn ignore<T>(_x: T) { }
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
/// original value of `*ptr`.
+228 -231
View File
@@ -47,12 +47,12 @@ unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
}
/// Returns true if a vector contains no elements
pub pure fn is_empty<T>(v: &[const T]) -> bool {
pub fn is_empty<T>(v: &[const T]) -> bool {
as_const_buf(v, |_p, len| len == 0u)
}
/// Returns true if two vectors have the same length
pub pure fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool {
pub fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool {
xs.len() == ys.len()
}
@@ -105,7 +105,7 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
/// Returns the number of elements the vector can hold without reallocating
#[inline(always)]
pub pure fn capacity<T>(v: &const ~[T]) -> uint {
pub fn capacity<T>(v: &const ~[T]) -> uint {
unsafe {
let repr: **raw::VecRepr = ::cast::transmute(v);
(**repr).unboxed.alloc / sys::nonzero_size_of::<T>()
@@ -114,12 +114,12 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
/// Returns the length of a vector
#[inline(always)]
pub pure fn len<T>(v: &[const T]) -> uint {
pub fn len<T>(v: &[const T]) -> uint {
as_const_buf(v, |_p, len| len)
}
// A botch to tide us over until core and std are fully demuted.
pub pure fn uniq_len<T>(v: &const ~[T]) -> uint {
pub fn uniq_len<T>(v: &const ~[T]) -> uint {
unsafe {
let v: &~[T] = ::cast::transmute(v);
as_const_buf(*v, |_p, len| len)
@@ -132,7 +132,7 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
pub fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
unsafe {
let mut v = with_capacity(n_elts);
do as_mut_buf(v) |p, _len| {
@@ -154,16 +154,16 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value `t`.
*/
pub pure fn from_elem<T:Copy>(n_elts: uint, t: T) -> ~[T] {
pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> ~[T] {
from_fn(n_elts, |_i| copy t)
}
/// Creates a new unique vector with the same contents as the slice
pub pure fn from_slice<T:Copy>(t: &[T]) -> ~[T] {
pub fn from_slice<T:Copy>(t: &[T]) -> ~[T] {
from_fn(t.len(), |i| t[i])
}
pub pure fn with_capacity<T>(capacity: uint) -> ~[T] {
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
let mut vec = ~[];
unsafe { reserve(&mut vec, capacity); }
vec
@@ -182,8 +182,7 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build_sized<A>(size: uint,
builder: &fn(push: &pure fn(v: A))) -> ~[A] {
pub fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> ~[A] {
let mut vec = with_capacity(size);
builder(|x| unsafe { vec.push(x) });
vec
@@ -200,7 +199,7 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> ~[A] {
pub fn build<A>(builder: &fn(push: &fn(v: A))) -> ~[A] {
build_sized(4, builder)
}
@@ -217,54 +216,55 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: &pure fn(v: A))) -> ~[A] {
pub fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: &fn(v: A)))
-> ~[A] {
build_sized(size.get_or_default(4), builder)
}
// Accessors
/// Returns the first element of a vector
pub pure fn head<T>(v: &'r [T]) -> &'r T {
pub fn head<T>(v: &'r [T]) -> &'r T {
if v.len() == 0 { fail!(~"head: empty vector") }
&v[0]
}
/// Returns `Some(x)` where `x` is the first element of the slice `v`,
/// or `None` if the vector is empty.
pub pure fn head_opt<T>(v: &'r [T]) -> Option<&'r T> {
pub fn head_opt<T>(v: &'r [T]) -> Option<&'r T> {
if v.len() == 0 { None } else { Some(&v[0]) }
}
/// Returns a vector containing all but the first element of a slice
pub pure fn tail<T>(v: &'r [T]) -> &'r [T] { slice(v, 1, v.len()) }
pub fn tail<T>(v: &'r [T]) -> &'r [T] { slice(v, 1, v.len()) }
/// Returns a vector containing all but the first `n` elements of a slice
pub pure fn tailn<T>(v: &'r [T], n: uint) -> &'r [T] { slice(v, n, v.len()) }
pub fn tailn<T>(v: &'r [T], n: uint) -> &'r [T] { slice(v, n, v.len()) }
/// Returns a vector containing all but the last element of a slice
pub pure fn init<T>(v: &'r [T]) -> &'r [T] { slice(v, 0, v.len() - 1) }
pub fn init<T>(v: &'r [T]) -> &'r [T] { slice(v, 0, v.len() - 1) }
/// Returns a vector containing all but the last `n' elements of a slice
pub pure fn initn<T>(v: &'r [T], n: uint) -> &'r [T] {
pub fn initn<T>(v: &'r [T], n: uint) -> &'r [T] {
slice(v, 0, v.len() - n)
}
/// Returns the last element of the slice `v`, failing if the slice is empty.
pub pure fn last<T>(v: &'r [T]) -> &'r T {
pub fn last<T>(v: &'r [T]) -> &'r T {
if v.len() == 0 { fail!(~"last: empty vector") }
&v[v.len() - 1]
}
/// Returns `Some(x)` where `x` is the last element of the slice `v`, or
/// `None` if the vector is empty.
pub pure fn last_opt<T>(v: &'r [T]) -> Option<&'r T> {
pub fn last_opt<T>(v: &'r [T]) -> Option<&'r T> {
if v.len() == 0 { None } else { Some(&v[v.len() - 1]) }
}
/// Return a slice that points into another slice.
#[inline(always)]
pub pure fn slice<T>(v: &'r [T], start: uint, end: uint) -> &'r [T] {
pub fn slice<T>(v: &'r [T], start: uint, end: uint) -> &'r [T] {
fail_unless!(start <= end);
fail_unless!(end <= len(v));
do as_imm_buf(v) |p, _len| {
@@ -278,10 +278,7 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
/// Return a slice that points into another slice.
#[inline(always)]
pub pure fn mut_slice<T>(v: &'r mut [T],
start: uint,
end: uint)
-> &'r mut [T] {
pub fn mut_slice<T>(v: &'r mut [T], start: uint, end: uint) -> &'r mut [T] {
fail_unless!(start <= end);
fail_unless!(end <= v.len());
do as_mut_buf(v) |p, _len| {
@@ -295,10 +292,8 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
/// Return a slice that points into another slice.
#[inline(always)]
pub pure fn const_slice<T>(v: &'r [const T],
start: uint,
end: uint)
-> &'r [const T] {
pub fn const_slice<T>(v: &'r [const T], start: uint, end: uint)
-> &'r [const T] {
fail_unless!(start <= end);
fail_unless!(end <= len(v));
do as_const_buf(v) |p, _len| {
@@ -434,7 +429,7 @@ pub fn partition<T>(v: ~[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) {
* Partitions a vector into two new vectors: those that satisfies the
* predicate, and those that do not.
*/
pub pure fn partitioned<T:Copy>(v: &[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) {
pub fn partitioned<T:Copy>(v: &[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) {
let mut lefts = ~[];
let mut rights = ~[];
@@ -713,7 +708,7 @@ pub fn dedup<T:Eq>(v: &mut ~[T]) {
// Appending
#[inline(always)]
pub pure fn append<T:Copy>(lhs: ~[T], rhs: &[const T]) -> ~[T] {
pub fn append<T:Copy>(lhs: ~[T], rhs: &[const T]) -> ~[T] {
let mut v = lhs;
unsafe {
v.push_all(rhs);
@@ -722,7 +717,7 @@ pub fn dedup<T:Eq>(v: &mut ~[T]) {
}
#[inline(always)]
pub pure fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
pub fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
let mut v = lhs;
unsafe { v.push(x); }
v
@@ -788,7 +783,7 @@ pub fn grow_set<T:Copy>(v: &mut ~[T], index: uint, initval: &T, val: T) {
// Functional utilities
/// Apply a function to each element of a vector and return the results
pub pure fn map<T, U>(v: &[T], f: &fn(t: &T) -> U) -> ~[U] {
pub fn map<T, U>(v: &[T], f: &fn(t: &T) -> U) -> ~[U] {
let mut result = with_capacity(len(v));
for each(v) |elem| {
unsafe {
@@ -807,7 +802,7 @@ pub fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U] {
}
/// Apply a function to each element of a vector and return the results
pub pure fn mapi<T, U>(v: &[T], f: &fn(uint, t: &T) -> U) -> ~[U] {
pub fn mapi<T, U>(v: &[T], f: &fn(uint, t: &T) -> U) -> ~[U] {
let mut i = 0;
do map(v) |e| {
i += 1;
@@ -819,14 +814,14 @@ pub fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U] {
* Apply a function to each element of a vector and return a concatenation
* of each result vector
*/
pub pure fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
pub fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] {
let mut result = ~[];
for each(v) |elem| { unsafe{ result.push_all_move(f(elem)); } }
result
}
/// Apply a function to each pair of elements and return the results
pub pure fn map2<T:Copy,U:Copy,V>(v0: &[T], v1: &[U],
pub fn map2<T:Copy,U:Copy,V>(v0: &[T], v1: &[U],
f: &fn(t: &T, v: &U) -> V) -> ~[V] {
let v0_len = len(v0);
if v0_len != len(v1) { fail!(); }
@@ -860,7 +855,7 @@ pub fn filter_map<T, U>(
result
}
pub pure fn filter_mapped<T, U: Copy>(
pub fn filter_mapped<T, U: Copy>(
v: &[T],
f: &fn(t: &T) -> Option<U>) -> ~[U]
{
@@ -904,7 +899,7 @@ pub fn filter<T>(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] {
* Apply function `f` to each element of `v` and return a vector containing
* only those elements for which `f` returned true.
*/
pub pure fn filtered<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] {
pub fn filtered<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] {
let mut result = ~[];
for each(v) |elem| {
if f(elem) { unsafe { result.push(*elem); } }
@@ -915,7 +910,7 @@ pub fn filter<T>(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] {
/**
* Like `filter()`, but in place. Preserves order of `v`. Linear time.
*/
pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
pub fn retain<T>(v: &mut ~[T], f: &fn(t: &T) -> bool) {
let len = v.len();
let mut deleted: uint = 0;
@@ -937,14 +932,14 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
*
* Flattens a vector of vectors of T into a single vector of T.
*/
pub pure fn concat<T:Copy>(v: &[~[T]]) -> ~[T] {
pub fn concat<T:Copy>(v: &[~[T]]) -> ~[T] {
let mut r = ~[];
for each(v) |inner| { unsafe { r.push_all(*inner); } }
r
}
/// Concatenate a vector of vectors, placing a given separator between each
pub pure fn connect<T:Copy>(v: &[~[T]], sep: &T) -> ~[T] {
pub fn connect<T:Copy>(v: &[~[T]], sep: &T) -> ~[T] {
let mut r: ~[T] = ~[];
let mut first = true;
for each(v) |inner| {
@@ -971,7 +966,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* ~~~
*
*/
pub pure fn foldl<T, U>(z: T, v: &[U], p: &fn(t: T, u: &U) -> T) -> T {
pub fn foldl<T, U>(z: T, v: &[U], p: &fn(t: T, u: &U) -> T) -> T {
let mut accum = z;
let mut i = 0;
let l = v.len();
@@ -1003,7 +998,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* ~~~
*
*/
pub pure fn foldr<T, U: Copy>(v: &[T], z: U, p: &fn(t: &T, u: U) -> U) -> U {
pub fn foldr<T, U: Copy>(v: &[T], z: U, p: &fn(t: &T, u: U) -> U) -> U {
let mut accum = z;
for v.each_reverse |elt| {
accum = p(elt, accum);
@@ -1016,7 +1011,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
*
* If the vector contains no elements then false is returned.
*/
pub pure fn any<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool {
pub fn any<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool {
for each(v) |elem| { if f(elem) { return true; } }
false
}
@@ -1026,7 +1021,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
*
* If the vectors contains no elements then false is returned.
*/
pub pure fn any2<T, U>(v0: &[T], v1: &[U],
pub fn any2<T, U>(v0: &[T], v1: &[U],
f: &fn(a: &T, b: &U) -> bool) -> bool {
let v0_len = len(v0);
let v1_len = len(v1);
@@ -1043,7 +1038,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
*
* If the vector contains no elements then true is returned.
*/
pub pure fn all<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool {
pub fn all<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool {
for each(v) |elem| { if !f(elem) { return false; } }
true
}
@@ -1053,7 +1048,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
*
* If the vector contains no elements then true is returned.
*/
pub pure fn alli<T>(v: &[T], f: &fn(uint, t: &T) -> bool) -> bool {
pub fn alli<T>(v: &[T], f: &fn(uint, t: &T) -> bool) -> bool {
for eachi(v) |i, elem| { if !f(i, elem) { return false; } }
true
}
@@ -1063,7 +1058,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
*
* If the vectors are not the same size then false is returned.
*/
pub pure fn all2<T, U>(v0: &[T], v1: &[U],
pub fn all2<T, U>(v0: &[T], v1: &[U],
f: &fn(t: &T, u: &U) -> bool) -> bool {
let v0_len = len(v0);
if v0_len != len(v1) { return false; }
@@ -1073,13 +1068,13 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
}
/// Return true if a vector contains an element with the given value
pub pure fn contains<T:Eq>(v: &[T], x: &T) -> bool {
pub fn contains<T:Eq>(v: &[T], x: &T) -> bool {
for each(v) |elt| { if *x == *elt { return true; } }
false
}
/// Returns the number of elements that are equal to a given value
pub pure fn count<T:Eq>(v: &[T], x: &T) -> uint {
pub fn count<T:Eq>(v: &[T], x: &T) -> uint {
let mut cnt = 0u;
for each(v) |elt| { if *x == *elt { cnt += 1u; } }
cnt
@@ -1092,7 +1087,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned.
*/
pub pure fn find<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
pub fn find<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
find_between(v, 0u, len(v), f)
}
@@ -1103,7 +1098,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* [`start`, `end`). When function `f` returns true then an option containing
* the element is returned. If `f` matches no elements then none is returned.
*/
pub pure fn find_between<T:Copy>(v: &[T], start: uint, end: uint,
pub fn find_between<T:Copy>(v: &[T], start: uint, end: uint,
f: &fn(t: &T) -> bool) -> Option<T> {
position_between(v, start, end, f).map(|i| v[*i])
}
@@ -1115,7 +1110,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* `f` returns true then an option containing the element is returned. If `f`
* matches no elements then none is returned.
*/
pub pure fn rfind<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
pub fn rfind<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> {
rfind_between(v, 0u, len(v), f)
}
@@ -1126,13 +1121,16 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* [`start`, `end`). When function `f` returns true then an option containing
* the element is returned. If `f` matches no elements then none is return.
*/
pub pure fn rfind_between<T:Copy>(v: &[T], start: uint, end: uint,
f: &fn(t: &T) -> bool) -> Option<T> {
pub fn rfind_between<T:Copy>(v: &[T],
start: uint,
end: uint,
f: &fn(t: &T) -> bool)
-> Option<T> {
rposition_between(v, start, end, f).map(|i| v[*i])
}
/// Find the first index containing a matching value
pub pure fn position_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
pub fn position_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
position(v, |y| *x == *y)
}
@@ -1143,7 +1141,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* then an option containing the index is returned. If `f` matches no elements
* then none is returned.
*/
pub pure fn position<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
pub fn position<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
position_between(v, 0u, len(v), f)
}
@@ -1154,8 +1152,11 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* [`start`, `end`). When function `f` returns true then an option containing
* the index is returned. If `f` matches no elements then none is returned.
*/
pub pure fn position_between<T>(v: &[T], start: uint, end: uint,
f: &fn(t: &T) -> bool) -> Option<uint> {
pub fn position_between<T>(v: &[T],
start: uint,
end: uint,
f: &fn(t: &T) -> bool)
-> Option<uint> {
fail_unless!(start <= end);
fail_unless!(end <= len(v));
let mut i = start;
@@ -1164,7 +1165,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
}
/// Find the last index containing a matching value
pure fn rposition_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
pub fn rposition_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> {
rposition(v, |y| *x == *y)
}
@@ -1175,7 +1176,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* `f` returns true then an option containing the index is returned. If `f`
* matches no elements then none is returned.
*/
pub pure fn rposition<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
pub fn rposition<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> {
rposition_between(v, 0u, len(v), f)
}
@@ -1187,7 +1188,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* containing the index is returned. If `f` matches no elements then none is
* returned.
*/
pub pure fn rposition_between<T>(v: &[T], start: uint, end: uint,
pub fn rposition_between<T>(v: &[T], start: uint, end: uint,
f: &fn(t: &T) -> bool) -> Option<uint> {
fail_unless!(start <= end);
fail_unless!(end <= len(v));
@@ -1206,7 +1207,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
/**
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
*/
pure fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
let mut ts = ~[], us = ~[];
for each(v) |p| {
let (t, u) = *p;
@@ -1226,7 +1227,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* and the i-th element of the second vector contains the second element
* of the i-th tuple of the input vector.
*/
pub pure fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
let mut ts = ~[], us = ~[];
unsafe {
do consume(v) |_i, p| {
@@ -1241,7 +1242,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
/**
* Convert two vectors to a vector of pairs, by reference. As zip().
*/
pub pure fn zip_slice<T:Copy,U:Copy>(v: &[const T], u: &[const U])
pub fn zip_slice<T:Copy,U:Copy>(v: &[const T], u: &[const U])
-> ~[(T, U)] {
let mut zipped = ~[];
let sz = len(v);
@@ -1259,7 +1260,7 @@ pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) {
* Returns a vector of tuples, where the i-th tuple contains contains the
* i-th elements from each of the input vectors.
*/
pub pure fn zip<T, U>(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] {
pub fn zip<T, U>(mut v: ~[T], mut u: ~[U]) -> ~[(T, U)] {
let mut i = len(v);
fail_unless!(i == len(u));
let mut w = with_capacity(i);
@@ -1292,7 +1293,7 @@ pub fn reverse<T>(v: &mut [T]) {
}
/// Returns a vector with the order of elements reversed
pub pure fn reversed<T:Copy>(v: &[const T]) -> ~[T] {
pub fn reversed<T:Copy>(v: &[const T]) -> ~[T] {
let mut rs: ~[T] = ~[];
let mut i = len::<T>(v);
if i == 0 { return (rs); } else { i -= 1; }
@@ -1342,7 +1343,7 @@ pub fn reverse<T>(v: &mut [T]) {
* ~~~
*/
#[inline(always)]
pub pure fn each<T>(v: &'r [T], f: &fn(&'r T) -> bool) {
pub fn each<T>(v: &'r [T], f: &fn(&'r T) -> bool) {
// ^^^^
// NB---this CANNOT be &[const T]! The reason
// is that you are passing it to `f()` using
@@ -1380,7 +1381,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
/// Like `each()`, but for the case where you have a vector that *may or may
/// not* have mutable contents.
#[inline(always)]
pub pure fn each_const<T>(v: &[const T], f: &fn(elem: &const T) -> bool) {
pub fn each_const<T>(v: &[const T], f: &fn(elem: &const T) -> bool) {
let mut i = 0;
let n = v.len();
while i < n {
@@ -1397,7 +1398,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
* Return true to continue, false to break.
*/
#[inline(always)]
pub pure fn eachi<T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) {
pub fn eachi<T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) {
let mut i = 0;
for each(v) |p| {
if !f(i, p) { return; }
@@ -1411,7 +1412,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
* Return true to continue, false to break.
*/
#[inline(always)]
pub pure fn each_reverse<T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) {
pub fn each_reverse<T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) {
eachi_reverse(v, |_i, v| blk(v))
}
@@ -1421,7 +1422,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
* Return true to continue, false to break.
*/
#[inline(always)]
pub pure fn eachi_reverse<T>(v: &'r [T], blk: &fn(i: uint, v: &'r T) -> bool) {
pub fn eachi_reverse<T>(v: &'r [T], blk: &fn(i: uint, v: &'r T) -> bool) {
let mut i = v.len();
while i > 0 {
i -= 1;
@@ -1439,7 +1440,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
* Both vectors must have the same length
*/
#[inline]
pub pure fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) {
pub fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) {
fail_unless!(len(v1) == len(v2));
for uint::range(0u, len(v1)) |i| {
if !f(&v1[i], &v2[i]) {
@@ -1458,7 +1459,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
* The total number of permutations produced is `len(v)!`. If `v` contains
* repeated elements, then some permutations are repeated.
*/
pub pure fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) {
pub fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) {
let ln = len(v);
if ln <= 1 {
put(v);
@@ -1482,7 +1483,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
}
}
pub pure fn windowed<TT:Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
pub fn windowed<TT:Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
let mut ww = ~[];
fail_unless!(1u <= nn);
for vec::eachi (xx) |ii, _x| {
@@ -1503,9 +1504,9 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
* foreign interop.
*/
#[inline(always)]
pub pure fn as_imm_buf<T,U>(s: &[T],
/* NB---this CANNOT be const, see below */
f: &fn(*T, uint) -> U) -> U {
pub fn as_imm_buf<T,U>(s: &[T],
/* NB---this CANNOT be const, see below */
f: &fn(*T, uint) -> U) -> U {
// NB---Do not change the type of s to `&[const T]`. This is
// unsound. The reason is that we are going to create immutable pointers
@@ -1523,9 +1524,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
/// Similar to `as_imm_buf` but passing a `*const T`
#[inline(always)]
pub pure fn as_const_buf<T,U>(s: &[const T],
f: &fn(*const T, uint) -> U) -> U {
pub fn as_const_buf<T,U>(s: &[const T], f: &fn(*const T, uint) -> U) -> U {
unsafe {
let v : *(*const T,uint) =
::cast::reinterpret_cast(&addr_of(&s));
@@ -1536,9 +1535,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
/// Similar to `as_imm_buf` but passing a `*mut T`
#[inline(always)]
pub pure fn as_mut_buf<T,U>(s: &mut [T],
f: &fn(*mut T, uint) -> U) -> U {
pub fn as_mut_buf<T,U>(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U {
unsafe {
let v : *(*mut T,uint) =
::cast::reinterpret_cast(&addr_of(&s));
@@ -1549,7 +1546,7 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
// Equality
pure fn eq<T:Eq>(a: &[T], b: &[T]) -> bool {
fn eq<T:Eq>(a: &[T], b: &[T]) -> bool {
let (a_len, b_len) = (a.len(), b.len());
if a_len != b_len { return false; }
@@ -1565,37 +1562,37 @@ pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
#[cfg(notest)]
impl<T:Eq> Eq for &'self [T] {
#[inline(always)]
pure fn eq(&self, other: & &'self [T]) -> bool { eq((*self), (*other)) }
fn eq(&self, other: & &'self [T]) -> bool { eq((*self), (*other)) }
#[inline(always)]
pure fn ne(&self, other: & &'self [T]) -> bool { !(*self).eq(other) }
fn ne(&self, other: & &'self [T]) -> bool { !(*self).eq(other) }
}
#[cfg(notest)]
impl<T:Eq> Eq for ~[T] {
#[inline(always)]
pure fn eq(&self, other: &~[T]) -> bool { eq((*self), (*other)) }
fn eq(&self, other: &~[T]) -> bool { eq((*self), (*other)) }
#[inline(always)]
pure fn ne(&self, other: &~[T]) -> bool { !(*self).eq(other) }
fn ne(&self, other: &~[T]) -> bool { !(*self).eq(other) }
}
#[cfg(notest)]
impl<T:Eq> Eq for @[T] {
#[inline(always)]
pure fn eq(&self, other: &@[T]) -> bool { eq((*self), (*other)) }
fn eq(&self, other: &@[T]) -> bool { eq((*self), (*other)) }
#[inline(always)]
pure fn ne(&self, other: &@[T]) -> bool { !(*self).eq(other) }
fn ne(&self, other: &@[T]) -> bool { !(*self).eq(other) }
}
#[cfg(notest)]
impl<T:Eq> Equiv<~[T]> for &'self [T] {
#[inline(always)]
pure fn equiv(&self, other: &~[T]) -> bool { eq(*self, *other) }
fn equiv(&self, other: &~[T]) -> bool { eq(*self, *other) }
}
// Lexicographical comparison
pure fn cmp<T: TotalOrd>(a: &[T], b: &[T]) -> Ordering {
fn cmp<T: TotalOrd>(a: &[T], b: &[T]) -> Ordering {
let low = uint::min(a.len(), b.len());
for uint::range(0, low) |idx| {
@@ -1612,22 +1609,22 @@ impl<T:Eq> Equiv<~[T]> for &'self [T] {
#[cfg(notest)]
impl<T: TotalOrd> TotalOrd for &'self [T] {
#[inline(always)]
pure fn cmp(&self, other: & &'self [T]) -> Ordering { cmp(*self, *other) }
fn cmp(&self, other: & &'self [T]) -> Ordering { cmp(*self, *other) }
}
#[cfg(notest)]
impl<T: TotalOrd> TotalOrd for ~[T] {
#[inline(always)]
pure fn cmp(&self, other: &~[T]) -> Ordering { cmp(*self, *other) }
fn cmp(&self, other: &~[T]) -> Ordering { cmp(*self, *other) }
}
#[cfg(notest)]
impl<T: TotalOrd> TotalOrd for @[T] {
#[inline(always)]
pure fn cmp(&self, other: &@[T]) -> Ordering { cmp(*self, *other) }
fn cmp(&self, other: &@[T]) -> Ordering { cmp(*self, *other) }
}
pure fn lt<T:Ord>(a: &[T], b: &[T]) -> bool {
fn lt<T:Ord>(a: &[T], b: &[T]) -> bool {
let (a_len, b_len) = (a.len(), b.len());
let mut end = uint::min(a_len, b_len);
@@ -1642,44 +1639,44 @@ impl<T: TotalOrd> TotalOrd for @[T] {
a_len < b_len
}
pure fn le<T:Ord>(a: &[T], b: &[T]) -> bool { !lt(b, a) }
pure fn ge<T:Ord>(a: &[T], b: &[T]) -> bool { !lt(a, b) }
pure fn gt<T:Ord>(a: &[T], b: &[T]) -> bool { lt(b, a) }
fn le<T:Ord>(a: &[T], b: &[T]) -> bool { !lt(b, a) }
fn ge<T:Ord>(a: &[T], b: &[T]) -> bool { !lt(a, b) }
fn gt<T:Ord>(a: &[T], b: &[T]) -> bool { lt(b, a) }
#[cfg(notest)]
impl<T:Ord> Ord for &'self [T] {
#[inline(always)]
pure fn lt(&self, other: & &'self [T]) -> bool { lt((*self), (*other)) }
fn lt(&self, other: & &'self [T]) -> bool { lt((*self), (*other)) }
#[inline(always)]
pure fn le(&self, other: & &'self [T]) -> bool { le((*self), (*other)) }
fn le(&self, other: & &'self [T]) -> bool { le((*self), (*other)) }
#[inline(always)]
pure fn ge(&self, other: & &'self [T]) -> bool { ge((*self), (*other)) }
fn ge(&self, other: & &'self [T]) -> bool { ge((*self), (*other)) }
#[inline(always)]
pure fn gt(&self, other: & &'self [T]) -> bool { gt((*self), (*other)) }
fn gt(&self, other: & &'self [T]) -> bool { gt((*self), (*other)) }
}
#[cfg(notest)]
impl<T:Ord> Ord for ~[T] {
#[inline(always)]
pure fn lt(&self, other: &~[T]) -> bool { lt((*self), (*other)) }
fn lt(&self, other: &~[T]) -> bool { lt((*self), (*other)) }
#[inline(always)]
pure fn le(&self, other: &~[T]) -> bool { le((*self), (*other)) }
fn le(&self, other: &~[T]) -> bool { le((*self), (*other)) }
#[inline(always)]
pure fn ge(&self, other: &~[T]) -> bool { ge((*self), (*other)) }
fn ge(&self, other: &~[T]) -> bool { ge((*self), (*other)) }
#[inline(always)]
pure fn gt(&self, other: &~[T]) -> bool { gt((*self), (*other)) }
fn gt(&self, other: &~[T]) -> bool { gt((*self), (*other)) }
}
#[cfg(notest)]
impl<T:Ord> Ord for @[T] {
#[inline(always)]
pure fn lt(&self, other: &@[T]) -> bool { lt((*self), (*other)) }
fn lt(&self, other: &@[T]) -> bool { lt((*self), (*other)) }
#[inline(always)]
pure fn le(&self, other: &@[T]) -> bool { le((*self), (*other)) }
fn le(&self, other: &@[T]) -> bool { le((*self), (*other)) }
#[inline(always)]
pure fn ge(&self, other: &@[T]) -> bool { ge((*self), (*other)) }
fn ge(&self, other: &@[T]) -> bool { ge((*self), (*other)) }
#[inline(always)]
pure fn gt(&self, other: &@[T]) -> bool { gt((*self), (*other)) }
fn gt(&self, other: &@[T]) -> bool { gt((*self), (*other)) }
}
#[cfg(notest)]
@@ -1690,7 +1687,7 @@ pub mod traits {
impl<T:Copy> Add<&'self [const T],~[T]> for ~[T] {
#[inline(always)]
pure fn add(&self, rhs: & &'self [const T]) -> ~[T] {
fn add(&self, rhs: & &'self [const T]) -> ~[T] {
append(copy *self, (*rhs))
}
}
@@ -1699,22 +1696,22 @@ impl<T:Copy> Add<&'self [const T],~[T]> for ~[T] {
impl<T> Container for &'self [const T] {
/// Returns true if a vector contains no elements
#[inline]
pure fn is_empty(&const self) -> bool { is_empty(*self) }
fn is_empty(&const self) -> bool { is_empty(*self) }
/// Returns the length of a vector
#[inline]
pure fn len(&const self) -> uint { len(*self) }
fn len(&const self) -> uint { len(*self) }
}
pub trait CopyableVector<T> {
pure fn to_owned(&self) -> ~[T];
fn to_owned(&self) -> ~[T];
}
/// Extension methods for vectors
impl<T: Copy> CopyableVector<T> for &'self [const T] {
/// Returns a copy of `v`.
#[inline]
pure fn to_owned(&self) -> ~[T] {
fn to_owned(&self) -> ~[T] {
let mut result = ~[];
// FIXME: #4568
unsafe {
@@ -1729,93 +1726,93 @@ impl<T: Copy> CopyableVector<T> for &'self [const T] {
}
pub trait ImmutableVector<T> {
pure fn slice(&self, start: uint, end: uint) -> &'self [T];
pure fn head(&self) -> &'self T;
pure fn head_opt(&self) -> Option<&'self T>;
pure fn tail(&self) -> &'self [T];
pure fn tailn(&self, n: uint) -> &'self [T];
pure fn init(&self) -> &'self [T];
pure fn initn(&self, n: uint) -> &'self [T];
pure fn last(&self) -> &'self T;
pure fn last_opt(&self) -> Option<&'self T>;
pure fn each_reverse(&self, blk: &fn(&T) -> bool);
pure fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool);
pure fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U;
pure fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U];
pure fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U];
fn slice(&self, start: uint, end: uint) -> &'self [T];
fn head(&self) -> &'self T;
fn head_opt(&self) -> Option<&'self T>;
fn tail(&self) -> &'self [T];
fn tailn(&self, n: uint) -> &'self [T];
fn init(&self) -> &'self [T];
fn initn(&self, n: uint) -> &'self [T];
fn last(&self) -> &'self T;
fn last_opt(&self) -> Option<&'self T>;
fn each_reverse(&self, blk: &fn(&T) -> bool);
fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool);
fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U;
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U];
fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U];
fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U];
pure fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool;
pure fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
pure fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U];
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool;
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U];
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U];
}
/// Extension methods for vectors
impl<T> ImmutableVector<T> for &'self [T] {
/// Return a slice that points into another slice.
#[inline]
pure fn slice(&self, start: uint, end: uint) -> &'self [T] {
fn slice(&self, start: uint, end: uint) -> &'self [T] {
slice(*self, start, end)
}
/// Returns the first element of a vector, failing if the vector is empty.
#[inline]
pure fn head(&self) -> &'self T { head(*self) }
fn head(&self) -> &'self T { head(*self) }
/// Returns the first element of a vector
#[inline]
pure fn head_opt(&self) -> Option<&'self T> { head_opt(*self) }
fn head_opt(&self) -> Option<&'self T> { head_opt(*self) }
/// Returns all but the first element of a vector
#[inline]
pure fn tail(&self) -> &'self [T] { tail(*self) }
fn tail(&self) -> &'self [T] { tail(*self) }
/// Returns all but the first `n' elements of a vector
#[inline]
pure fn tailn(&self, n: uint) -> &'self [T] { tailn(*self, n) }
fn tailn(&self, n: uint) -> &'self [T] { tailn(*self, n) }
/// Returns all but the last elemnt of a vector
#[inline]
pure fn init(&self) -> &'self [T] { init(*self) }
fn init(&self) -> &'self [T] { init(*self) }
/// Returns all but the last `n' elemnts of a vector
#[inline]
pure fn initn(&self, n: uint) -> &'self [T] { initn(*self, n) }
fn initn(&self, n: uint) -> &'self [T] { initn(*self, n) }
/// Returns the last element of a `v`, failing if the vector is empty.
#[inline]
pure fn last(&self) -> &'self T { last(*self) }
fn last(&self) -> &'self T { last(*self) }
/// Returns the last element of a `v`, failing if the vector is empty.
#[inline]
pure fn last_opt(&self) -> Option<&'self T> { last_opt(*self) }
fn last_opt(&self) -> Option<&'self T> { last_opt(*self) }
/// Iterates over a vector's elements in reverse.
#[inline]
pure fn each_reverse(&self, blk: &fn(&T) -> bool) {
fn each_reverse(&self, blk: &fn(&T) -> bool) {
each_reverse(*self, blk)
}
/// Iterates over a vector's elements and indices in reverse.
#[inline]
pure fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool) {
fn eachi_reverse(&self, blk: &fn(uint, &T) -> bool) {
eachi_reverse(*self, blk)
}
/// Reduce a vector from right to left
#[inline]
pure fn foldr<U:Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U {
fn foldr<U:Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U {
foldr(*self, z, p)
}
/// Apply a function to each element of a vector and return the results
#[inline]
pure fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) }
fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) }
/**
* Apply a function to the index and value of each element in the vector
* and return the results
*/
pure fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U] {
fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U] {
mapi(*self, f)
}
@@ -1835,7 +1832,7 @@ fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U] {
*
* If the vector is empty, true is returned.
*/
pure fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool {
fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool {
alli(*self, f)
}
/**
@@ -1843,7 +1840,7 @@ fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U] {
* of each result vector
*/
#[inline]
pure fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] {
fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] {
flat_map(*self, f)
}
/**
@@ -1853,16 +1850,16 @@ fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U] {
* the resulting vector.
*/
#[inline]
pure fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U] {
fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U] {
filter_mapped(*self, f)
}
}
pub trait ImmutableEqVector<T:Eq> {
pure fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
pure fn position_elem(&self, t: &T) -> Option<uint>;
pure fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
pure fn rposition_elem(&self, t: &T) -> Option<uint>;
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
fn position_elem(&self, t: &T) -> Option<uint>;
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>;
fn rposition_elem(&self, t: &T) -> Option<uint>;
}
impl<T:Eq> ImmutableEqVector<T> for &'self [T] {
@@ -1874,13 +1871,13 @@ impl<T:Eq> ImmutableEqVector<T> for &'self [T] {
* elements then none is returned.
*/
#[inline]
pure fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
position(*self, f)
}
/// Find the first index containing a matching value
#[inline]
pure fn position_elem(&self, x: &T) -> Option<uint> {
fn position_elem(&self, x: &T) -> Option<uint> {
position_elem(*self, x)
}
@@ -1892,21 +1889,21 @@ impl<T:Eq> ImmutableEqVector<T> for &'self [T] {
* returned. If `f` matches no elements then none is returned.
*/
#[inline]
pure fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> {
rposition(*self, f)
}
/// Find the last index containing a matching value
#[inline]
pure fn rposition_elem(&self, t: &T) -> Option<uint> {
fn rposition_elem(&self, t: &T) -> Option<uint> {
rposition_elem(*self, t)
}
}
pub trait ImmutableCopyableVector<T> {
pure fn filtered(&self, f: &fn(&T) -> bool) -> ~[T];
pure fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T>;
pure fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
fn filtered(&self, f: &fn(&T) -> bool) -> ~[T];
fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T>;
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
}
/// Extension methods for vectors
@@ -1919,7 +1916,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &'self [T] {
* containing only those elements for which `f` returned true.
*/
#[inline]
pure fn filtered(&self, f: &fn(t: &T) -> bool) -> ~[T] {
fn filtered(&self, f: &fn(t: &T) -> bool) -> ~[T] {
filtered(*self, f)
}
@@ -1931,7 +1928,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &'self [T] {
* returned. If `f` matches no elements then none is returned.
*/
#[inline]
pure fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T> {
fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T> {
rfind(*self, f)
}
@@ -1940,7 +1937,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &'self [T] {
* those that do not.
*/
#[inline]
pure fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]) {
partitioned(*self, f)
}
}
@@ -1955,10 +1952,10 @@ pub trait OwnedVector<T> {
fn remove(&mut self, i: uint) -> T;
fn swap_remove(&mut self, index: uint) -> T;
fn truncate(&mut self, newlen: uint);
fn retain(&mut self, f: &pure fn(t: &T) -> bool);
fn retain(&mut self, f: &fn(t: &T) -> bool);
fn consume(self, f: &fn(uint, v: T));
fn filter(self, f: &fn(t: &T) -> bool) -> ~[T];
fn partition(self, f: &pure fn(&T) -> bool) -> (~[T], ~[T]);
fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]);
fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>);
}
@@ -2009,7 +2006,7 @@ fn truncate(&mut self, newlen: uint) {
}
#[inline]
fn retain(&mut self, f: &pure fn(t: &T) -> bool) {
fn retain(&mut self, f: &fn(t: &T) -> bool) {
retain(self, f);
}
@@ -2258,7 +2255,7 @@ pub mod bytes {
use vec;
/// Bytewise string comparison
pub pure fn memcmp(a: &~[u8], b: &~[u8]) -> int {
pub fn memcmp(a: &~[u8], b: &~[u8]) -> int {
let a_len = a.len();
let b_len = b.len();
let n = uint::min(a_len, b_len) as libc::size_t;
@@ -2279,22 +2276,22 @@ pub mod bytes {
}
/// Bytewise less than or equal
pub pure fn lt(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) < 0 }
pub fn lt(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) < 0 }
/// Bytewise less than or equal
pub pure fn le(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) <= 0 }
pub fn le(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) <= 0 }
/// Bytewise equality
pub pure fn eq(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) == 0 }
pub fn eq(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) == 0 }
/// Bytewise inequality
pub pure fn ne(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) != 0 }
pub fn ne(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) != 0 }
/// Bytewise greater than or equal
pub pure fn ge(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) >= 0 }
pub fn ge(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) >= 0 }
/// Bytewise greater than
pub pure fn gt(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) > 0 }
pub fn gt(a: &~[u8], b: &~[u8]) -> bool { memcmp(a, b) > 0 }
/**
* Copies data from one vector to another.
@@ -2314,25 +2311,25 @@ pub fn copy_memory(dst: &mut [u8], src: &[const u8], count: uint) {
impl<A> iter::BaseIter<A> for &'self [A] {
#[inline(always)]
pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
// FIXME(#4148): This should be redundant
impl<A> iter::BaseIter<A> for ~[A] {
#[inline(always)]
pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
// FIXME(#4148): This should be redundant
impl<A> iter::BaseIter<A> for @[A] {
#[inline(always)]
pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
#[inline(always)]
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
}
impl<A> iter::MutableIter<A> for &'self mut [A] {
@@ -2359,25 +2356,25 @@ fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool) {
}
impl<A> iter::ExtendedIter<A> for &'self [A] {
pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
iter::eachi(self, blk)
}
pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool {
pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
iter::all(self, blk)
}
pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool {
pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
iter::any(self, blk)
}
pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
iter::foldl(self, b0, blk)
}
pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
iter::position(self, f)
}
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
iter::map_to_vec(self, op)
}
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B] {
iter::flat_map_to_vec(self, op)
}
@@ -2385,25 +2382,25 @@ impl<A> iter::ExtendedIter<A> for &'self [A] {
// FIXME(#4148): This should be redundant
impl<A> iter::ExtendedIter<A> for ~[A] {
pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
iter::eachi(self, blk)
}
pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool {
pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
iter::all(self, blk)
}
pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool {
pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
iter::any(self, blk)
}
pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
iter::foldl(self, b0, blk)
}
pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
iter::position(self, f)
}
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
iter::map_to_vec(self, op)
}
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B] {
iter::flat_map_to_vec(self, op)
}
@@ -2411,98 +2408,98 @@ impl<A> iter::ExtendedIter<A> for ~[A] {
// FIXME(#4148): This should be redundant
impl<A> iter::ExtendedIter<A> for @[A] {
pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
iter::eachi(self, blk)
}
pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool {
pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
iter::all(self, blk)
}
pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool {
pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
iter::any(self, blk)
}
pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
iter::foldl(self, b0, blk)
}
pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
iter::position(self, f)
}
pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
iter::map_to_vec(self, op)
}
pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B] {
iter::flat_map_to_vec(self, op)
}
}
impl<A:Eq> iter::EqIter<A> for &'self [A] {
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
pub fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
pub fn count(&self, x: &A) -> uint { iter::count(self, x) }
}
// FIXME(#4148): This should be redundant
impl<A:Eq> iter::EqIter<A> for ~[A] {
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
pub fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
pub fn count(&self, x: &A) -> uint { iter::count(self, x) }
}
// FIXME(#4148): This should be redundant
impl<A:Eq> iter::EqIter<A> for @[A] {
pub pure fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
pub pure fn count(&self, x: &A) -> uint { iter::count(self, x) }
pub fn contains(&self, x: &A) -> bool { iter::contains(self, x) }
pub fn count(&self, x: &A) -> uint { iter::count(self, x) }
}
impl<A:Copy> iter::CopyableIter<A> for &'self [A] {
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
iter::find(self, f)
}
}
// FIXME(#4148): This should be redundant
impl<A:Copy> iter::CopyableIter<A> for ~[A] {
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
iter::find(self, f)
}
}
// FIXME(#4148): This should be redundant
impl<A:Copy> iter::CopyableIter<A> for @[A] {
pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] {
iter::filter_to_vec(self, pred)
}
pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
fn to_vec(&self) -> ~[A] { iter::to_vec(self) }
pub fn find(&self, f: &fn(&A) -> bool) -> Option<A> {
iter::find(self, f)
}
}
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for &'self [A] {
pure fn min(&self) -> A { iter::min(self) }
pure fn max(&self) -> A { iter::max(self) }
fn min(&self) -> A { iter::min(self) }
fn max(&self) -> A { iter::max(self) }
}
// FIXME(#4148): This should be redundant
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for ~[A] {
pure fn min(&self) -> A { iter::min(self) }
pure fn max(&self) -> A { iter::max(self) }
fn min(&self) -> A { iter::min(self) }
fn max(&self) -> A { iter::max(self) }
}
// FIXME(#4148): This should be redundant
impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for @[A] {
pure fn min(&self) -> A { iter::min(self) }
pure fn max(&self) -> A { iter::max(self) }
fn min(&self) -> A { iter::min(self) }
fn max(&self) -> A { iter::max(self) }
}
impl<A:Copy> iter::CopyableNonstrictIter<A> for &'self [A] {
pure fn each_val(&const self, f: &fn(A) -> bool) {
fn each_val(&const self, f: &fn(A) -> bool) {
let mut i = 0;
while i < self.len() {
if !f(copy self[i]) { break; }
@@ -2513,7 +2510,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for &'self [A] {
// FIXME(#4148): This should be redundant
impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] {
pure fn each_val(&const self, f: &fn(A) -> bool) {
fn each_val(&const self, f: &fn(A) -> bool) {
let mut i = 0;
while i < uniq_len(self) {
if !f(copy self[i]) { break; }
@@ -2524,7 +2521,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] {
// FIXME(#4148): This should be redundant
impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
pure fn each_val(&const self, f: &fn(A) -> bool) {
fn each_val(&const self, f: &fn(A) -> bool) {
let mut i = 0;
while i < self.len() {
if !f(copy self[i]) { break; }
@@ -2559,11 +2556,11 @@ fn square(n: uint) -> uint { n * n }
fn square_ref(n: &uint) -> uint { square(*n) }
pure fn is_three(n: &uint) -> bool { *n == 3u }
fn is_three(n: &uint) -> bool { *n == 3u }
pure fn is_odd(n: &uint) -> bool { *n % 2u == 1u }
fn is_odd(n: &uint) -> bool { *n % 2u == 1u }
pure fn is_equal(x: &uint, y:&uint) -> bool { *x == *y }
fn is_equal(x: &uint, y:&uint) -> bool { *x == *y }
fn square_if_odd_r(n: &uint) -> Option<uint> {
if *n % 2u == 1u { Some(*n * *n) } else { None }