Adds documentation for various things that I understand.
Adds #[allow(missing_doc)] for lots of things that I don't understand.
}
// Appending
+
+/// Iterates over the `rhs` vector, copying each element and appending it to the
+/// `lhs`. Afterwards, the `lhs` is then returned for use again.
#[inline(always)]
pub fn append<T:Copy>(lhs: @[T], rhs: &const [T]) -> @[T] {
do build_sized(lhs.len() + rhs.len()) |push| {
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
}
+ /**
+ * Pushes a new value onto this vector.
+ */
#[inline(always)]
pub unsafe fn push<T>(v: &mut @[T], initval: T) {
let repr: **VecRepr = transmute_copy(&v);
}
#[inline(always)] // really pretty please
- pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
+ unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
let repr: **mut VecRepr = ::cast::transmute(v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>();
move_val_init(&mut(*p), initval);
}
- pub unsafe fn push_slow<T>(v: &mut @[T], initval: T) {
+ unsafe fn push_slow<T>(v: &mut @[T], initval: T) {
reserve_at_least(&mut *v, v.len() + 1u);
push_fast(v, initval);
}
dest
}
+/// Casts the value at `src` to U. The two types must have the same length.
#[cfg(target_word_size = "32", not(stage0))]
#[inline(always)]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
dest
}
+/// Casts the value at `src` to U. The two types must have the same length.
#[cfg(target_word_size = "64", not(stage0))]
#[inline(always)]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
#[mutable]
#[deriving(Clone, DeepClone, Eq)]
+#[allow(missing_doc)]
pub struct Cell<T> {
priv value: Option<T>
}
Cell { value: Some(value) }
}
+/// Creates a new empty cell with no value inside.
pub fn empty_cell<T>() -> Cell<T> {
Cell { value: None }
}
Cn Unassigned a reserved unassigned code point or a noncharacter
*/
+/// Returns whether the specified character is considered a unicode alphabetic
+/// character
pub fn is_alphabetic(c: char) -> bool { derived_property::Alphabetic(c) }
+#[allow(missing_doc)]
pub fn is_XID_start(c: char) -> bool { derived_property::XID_Start(c) }
+#[allow(missing_doc)]
pub fn is_XID_continue(c: char) -> bool { derived_property::XID_Continue(c) }
///
)
}
+#[allow(missing_doc)]
pub trait Char {
fn is_alphabetic(&self) -> bool;
fn is_XID_start(&self) -> bool;
use core::kinds::Const;
+/// A common trait for cloning an object.
pub trait Clone {
/// Returns a copy of the value. The contents of owned pointers
/// are copied to maintain uniqueness, while the contents of
clone_impl!(bool)
clone_impl!(char)
+/// A trait distinct from `Clone` which represents "deep copies" of things like
+/// managed boxes which would otherwise not be copied.
pub trait DeepClone {
/// Return a deep copy of the value. Unlike `Clone`, the contents of shared pointer types
/// *are* copied. Note that this is currently unimplemented for managed boxes, as
*/
+#[allow(missing_doc)];
+
/**
* Trait for values that can be compared for equality and inequality.
*
Message passing
*/
+#[allow(missing_doc)];
+
use cast::{transmute, transmute_mut};
use container::Container;
use either::{Either, Left, Right};
/*! Condition handling */
+#[allow(missing_doc)];
+
use local_data::{local_data_pop, local_data_set};
use local_data;
use prelude::*;
use option::Option;
+/// A trait to represent the abstract idea of a container. The only concrete
+/// knowledge known is the number of elements contained within.
pub trait Container {
/// Return the number of elements in the container
fn len(&const self) -> uint;
fn is_empty(&const self) -> bool;
}
+/// A trait to represent mutable containers
pub trait Mutable: Container {
/// Clear the container, removing all values.
fn clear(&mut self);
}
+/// A map is a key-value store where values may be looked up by their keys. This
+/// trait provides basic operations to operate on these stores.
pub trait Map<K, V>: Mutable {
/// Return true if the map contains a value for the specified key
fn contains_key(&self, key: &K) -> bool;
- // Visits all keys and values
+ /// Visits all keys and values
fn each<'a>(&'a self, f: &fn(&K, &'a V) -> bool) -> bool;
/// Visit all keys
fn pop(&mut self, k: &K) -> Option<V>;
}
+/// A set is a group of objects which are each distinct from one another. This
+/// trait represents actions which can be performed on sets to manipulate and
+/// iterate over them.
pub trait Set<T>: Mutable {
/// Return true if the set contains a value
fn contains(&self, value: &T) -> bool;
#[license = "MIT/ASL2"];
#[crate_type = "lib"];
+// NOTE: remove these two attributes after the next snapshot
+#[no_core]; // for stage0
+#[allow(unrecognized_lint)]; // otherwise stage0 is seriously ugly
// Don't link to std. We are std.
-#[no_core]; // for stage0
#[no_std];
#[deny(non_camel_case_types)];
+#[deny(missing_doc)];
// Make core testable by not duplicating lang items. See #2912
#[cfg(test)] extern mod realstd(name = "std");
use option::Option;
+/// A trait to abstract the idea of creating a new instance of a type from a
+/// string.
pub trait FromStr {
+ /// Parses a string `s` to return an optional value of this type. If the
+ /// string is ill-formatted, the None is returned.
fn from_str(s: &str) -> Option<Self>;
}
* CPRNG like rand::rng.
*/
+#[allow(missing_doc)];
+
use container::Container;
use old_iter::BaseIter;
use rt::io::Writer;
value: V,
}
+/// A hash map implementation which uses linear probing along with the SipHash
+/// hash function for internal state. This means that the order of all hash maps
+/// is randomized by keying each hash map randomly on creation.
+///
+/// It is required that the keys implement the `Eq` and `Hash` traits, although
+/// this can frequently be achieved by just implementing the `Eq` and
+/// `IterBytes` traits as `Hash` is automatically implemented for types that
+/// implement `IterBytes`.
pub struct HashMap<K,V> {
priv k0: u64,
priv k1: u64,
((capacity as float) * 3. / 4.) as uint
}
+/// Creates a new hash map with the specified capacity.
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
initial_capacity: uint) -> HashMap<K, V> {
let mut r = rand::task_rng();
fn ne(&self, other: &HashMap<K, V>) -> bool { !self.eq(other) }
}
+/// An implementation of a hash set using the underlying representation of a
+/// HashMap where the value is (). As with the `HashMap` type, a `HashSet`
+/// requires that the elements implement the `Eq` and `Hash` traits.
pub struct HashSet<T> {
priv map: HashMap<T, ()>
}
*/
+#[allow(missing_doc)];
+
use result::Result;
use container::Container;
use num::{One, Zero};
use ops::{Add, Mul};
+#[allow(missing_doc)]
pub trait Times {
fn times(&self, it: &fn() -> bool) -> bool;
}
use num;
use prelude::*;
+/// An interface for dealing with "external iterators". These types of iterators
+/// can be resumed at any time as all state is stored internally as opposed to
+/// being located on the call stack.
pub trait Iterator<A> {
/// Advance the iterator and return the next value. Return `None` when the end is reached.
fn next(&mut self) -> Option<A>;
///
/// In the future these will be default methods instead of a utility trait.
pub trait IteratorUtil<A> {
+ /// Chan this iterator with another, returning a new iterator which will
+ /// finish iterating over the current iterator, and then it will iterate
+ /// over the other specified iterator.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [0];
+ /// let b = [1];
+ /// let mut it = a.iter().chain(b.iter());
+ /// assert_eq!(it.next().get(), &0);
+ /// assert_eq!(it.next().get(), &1);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<Self, U>;
+
+ /// Creates an iterator which iterates over both this and the specified
+ /// iterators simultaneously, yielding the two elements as pairs. When
+ /// either iterator returns None, all further invocations of next() will
+ /// return None.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [0];
+ /// let b = [1];
+ /// let mut it = a.iter().zip(b.iter());
+ /// assert_eq!(it.next().get(), (&0, &1));
+ /// assert!(it.next().is_none());
+ /// ~~~
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<Self, U>;
+
// FIXME: #5898: should be called map
+ /// Creates a new iterator which will apply the specified function to each
+ /// element returned by the first, yielding the mapped element instead. This
+ /// similar to the `vec::map` function.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2];
+ /// let mut it = a.iter().transform(|&x| 2 * x);
+ /// assert_eq!(it.next().get(), 2);
+ /// assert_eq!(it.next().get(), 4);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn transform<'r, B>(self, f: &'r fn(A) -> B) -> MapIterator<'r, A, B, Self>;
+
+ /// Creates an iterator which applies the predicate to each element returned
+ /// by this iterator. Only elements which have the predicate evaluate to
+ /// `true` will be yielded.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2];
+ /// let mut it = a.iter().filter(|&x| *x > 1);
+ /// assert_eq!(it.next().get(), &2);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> FilterIterator<'r, A, Self>;
+
+ /// Creates an iterator which both filters and maps elements at the same
+ /// If the specified function returns None, the element is skipped.
+ /// Otherwise the option is unwrapped and the new value is yielded.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2];
+ /// let mut it = a.iter().filter_map(|&x| if x > 1 {Some(2 * x)} else {None});
+ /// assert_eq!(it.next().get(), 4);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn filter_map<'r, B>(self, f: &'r fn(A) -> Option<B>) -> FilterMapIterator<'r, A, B, Self>;
+
+ /// Creates an iterator which yields a pair of the value returned by this
+ /// iterator plus the current index of iteration.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [100, 200];
+ /// let mut it = a.iter().enumerate();
+ /// assert_eq!(it.next().get(), (0, &100));
+ /// assert_eq!(it.next().get(), (1, &200));
+ /// assert!(it.next().is_none());
+ /// ~~~
fn enumerate(self) -> EnumerateIterator<Self>;
+
+ /// Creates an iterator which invokes the predicate on elements until it
+ /// returns true. Once the predicate returns true, all further elements are
+ /// yielded.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 2, 1];
+ /// let mut it = a.iter().skip_while(|&a| *a < 3);
+ /// assert_eq!(it.next().get(), &3);
+ /// assert_eq!(it.next().get(), &2);
+ /// assert_eq!(it.next().get(), &1);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn skip_while<'r>(self, predicate: &'r fn(&A) -> bool) -> SkipWhileIterator<'r, A, Self>;
+
+ /// Creates an iterator which yields elements so long as the predicate
+ /// returns true. After the predicate returns false for the first time, no
+ /// further elements will be yielded.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 2, 1];
+ /// let mut it = a.iter().take_while(|&a| *a < 3);
+ /// assert_eq!(it.next().get(), &1);
+ /// assert_eq!(it.next().get(), &2);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn take_while<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhileIterator<'r, A, Self>;
+
+ /// Creates an iterator which skips the first `n` elements of this iterator,
+ /// and then it yields all further items.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// let mut it = a.iter().skip(3);
+ /// assert_eq!(it.next().get(), &4);
+ /// assert_eq!(it.next().get(), &5);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn skip(self, n: uint) -> SkipIterator<Self>;
+
+ /// Creates an iterator which yields the first `n` elements of this
+ /// iterator, and then it will always return None.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// let mut it = a.iter().take(3);
+ /// assert_eq!(it.next().get(), &1);
+ /// assert_eq!(it.next().get(), &2);
+ /// assert_eq!(it.next().get(), &3);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn take(self, n: uint) -> TakeIterator<Self>;
+
+ /// Creates a new iterator which behaves in a similar fashion to foldl.
+ /// There is a state which is passed between each iteration and can be
+ /// mutated as necessary. The yielded values from the closure are yielded
+ /// from the ScanIterator instance when not None.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// let mut it = a.iter().scan(1, |fac, &x| {
+ /// *fac = *fac * x;
+ /// Some(*fac)
+ /// });
+ /// assert_eq!(it.next().get(), 1);
+ /// assert_eq!(it.next().get(), 2);
+ /// assert_eq!(it.next().get(), 6);
+ /// assert_eq!(it.next().get(), 24);
+ /// assert_eq!(it.next().get(), 120);
+ /// assert!(it.next().is_none());
+ /// ~~~
fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
-> ScanIterator<'r, A, B, Self, St>;
+
+ /// An adaptation of an external iterator to the for-loop protocol of rust.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// for Counter::new(0, 10).advance |i| {
+ /// io::println(fmt!("%d", i));
+ /// }
+ /// ~~~
fn advance(&mut self, f: &fn(A) -> bool) -> bool;
+
+ /// Loops through the entire iterator, accumulating all of the elements into
+ /// a vector.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// let b = a.iter().transform(|&x| x).to_vec();
+ /// assert!(a == b);
+ /// ~~~
fn to_vec(&mut self) -> ~[A];
+
+ /// Loops through `n` iterations, returning the `n`th element of the
+ /// iterator.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// let mut it = a.iter();
+ /// assert!(it.nth(2).get() == &3);
+ /// assert!(it.nth(2) == None);
+ /// ~~~
fn nth(&mut self, n: uint) -> Option<A>;
+
+ /// Loops through the entire iterator, returning the last element of the
+ /// iterator.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// assert!(a.iter().last().get() == &5);
+ /// ~~~
fn last(&mut self) -> Option<A>;
+
+ /// Performs a fold operation over the entire iterator, returning the
+ /// eventual state at the end of the iteration.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// assert!(a.iter().fold(0, |a, &b| a + b) == 15);
+ /// ~~~
fn fold<B>(&mut self, start: B, f: &fn(B, A) -> B) -> B;
+
+ /// Counts the number of elements in this iterator.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// let mut it = a.iter();
+ /// assert!(it.count() == 5);
+ /// assert!(it.count() == 0);
+ /// ~~~
fn count(&mut self) -> uint;
+
+ /// Tests whether the predicate holds true for all elements in the iterator.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// assert!(a.iter().all(|&x| *x > 0));
+ /// assert!(!a.iter().all(|&x| *x > 2));
+ /// ~~~
fn all(&mut self, f: &fn(&A) -> bool) -> bool;
+
+ /// Tests whether any element of an iterator satisfies the specified
+ /// predicate.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// let mut it = a.iter();
+ /// assert!(it.any(|&x| *x == 3));
+ /// assert!(!it.any(|&x| *x == 3));
+ /// ~~~
fn any(&mut self, f: &fn(&A) -> bool) -> bool;
}
}
}
+/// A trait for iterators over elements which can be added together
pub trait AdditiveIterator<A> {
+ /// Iterates over the entire iterator, summing up all the elements
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// let mut it = a.iter().transform(|&x| x);
+ /// assert!(it.sum() == 15);
+ /// ~~~
fn sum(&mut self) -> A;
}
fn sum(&mut self) -> A { self.fold(Zero::zero::<A>(), |s, x| s + x) }
}
+/// A trait for iterators over elements whose elements can be multiplied
+/// together.
pub trait MultiplicativeIterator<A> {
+ /// Iterates over the entire iterator, multiplying all the elements
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// fn factorial(n: uint) -> uint {
+ /// Counter::new(1u, 1).take_while(|&i| i <= n).product()
+ /// }
+ /// assert!(factorial(0) == 1);
+ /// assert!(factorial(1) == 1);
+ /// assert!(factorial(5) == 120);
+ /// ~~~
fn product(&mut self) -> A;
}
fn product(&mut self) -> A { self.fold(One::one::<A>(), |p, x| p * x) }
}
+/// A trait for iterators over elements which can be compared to one another.
+/// The type of each element must ascribe to the `Ord` trait.
pub trait OrdIterator<A> {
+ /// Consumes the entire iterator to return the maximum element.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// assert!(a.iter().max().get() == &5);
+ /// ~~~
fn max(&mut self) -> Option<A>;
+
+ /// Consumes the entire iterator to return the minimum element.
+ ///
+ /// # Example
+ ///
+ /// ~~~ {.rust}
+ /// use std::iterator::*;
+ ///
+ /// let a = [1, 2, 3, 4, 5];
+ /// assert!(a.iter().min().get() == &1);
+ /// ~~~
fn min(&mut self) -> Option<A>;
}
}
}
+/// An iterator which strings two iterators together
pub struct ChainIterator<T, U> {
priv a: T,
priv b: U,
}
}
+/// An iterator which iterates two other iterators simultaneously
pub struct ZipIterator<T, U> {
priv a: T,
priv b: U
}
}
+/// An iterator which maps the values of `iter` with `f`
pub struct MapIterator<'self, A, B, T> {
priv iter: T,
priv f: &'self fn(A) -> B
}
}
+/// An iterator which filters the elements of `iter` with `predicate`
pub struct FilterIterator<'self, A, T> {
priv iter: T,
priv predicate: &'self fn(&A) -> bool
}
}
+/// An iterator which uses `f` to both filter and map elements from `iter`
pub struct FilterMapIterator<'self, A, B, T> {
priv iter: T,
priv f: &'self fn(A) -> Option<B>
}
}
+/// An iterator which yields the current count and the element during iteration
pub struct EnumerateIterator<T> {
priv iter: T,
priv count: uint
}
}
+/// An iterator which rejects elements while `predicate` is true
pub struct SkipWhileIterator<'self, A, T> {
priv iter: T,
priv flag: bool,
}
}
+/// An iterator which only accepts elements while `predicate` is true
pub struct TakeWhileIterator<'self, A, T> {
priv iter: T,
priv flag: bool,
}
}
+/// An iterator which skips over `n` elements of `iter`
pub struct SkipIterator<T> {
priv iter: T,
priv n: uint
}
}
+/// An iterator which only iterates over the first `n` iterations of `iter`.
pub struct TakeIterator<T> {
priv iter: T,
priv n: uint
}
}
+/// An iterator to maintain state while iterating another iterator
pub struct ScanIterator<'self, A, B, T, St> {
priv iter: T,
priv f: &'self fn(&mut St, A) -> Option<B>,
+
+ /// The current internal state to be passed to the closure next.
state: St
}
}
}
+/// An iterator which just modifies the contained state throughout iteration.
pub struct UnfoldrIterator<'self, A, St> {
priv f: &'self fn(&mut St) -> Option<A>,
+ /// Internal state that will be yielded on the next iteration
state: St
}
-pub impl<'self, A, St> UnfoldrIterator<'self, A, St> {
+impl<'self, A, St> UnfoldrIterator<'self, A, St> {
+ /// Creates a new iterator with the specified closure as the "iterator
+ /// function" and an initial state to eventually pass to the iterator
#[inline]
- fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St)
+ pub fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St)
-> UnfoldrIterator<'self, A, St> {
UnfoldrIterator {
f: f,
}
}
-/// An infinite iterator starting at `start` and advancing by `step` with each iteration
+/// An infinite iterator starting at `start` and advancing by `step` with each
+/// iteration
pub struct Counter<A> {
+ /// The current state the counter is at (next value to be yielded)
state: A,
+ /// The amount that this iterator is stepping by
step: A
}
-pub impl<A> Counter<A> {
+impl<A> Counter<A> {
+ /// Creates a new counter with the specified start/step
#[inline(always)]
- fn new(start: A, step: A) -> Counter<A> {
+ pub fn new(start: A, step: A) -> Counter<A> {
Counter{state: start, step: step}
}
}
*/
+#[allow(missing_doc)];
+
#[lang="copy"]
pub trait Copy {
// Empty.
*/
#[allow(non_camel_case_types)];
+#[allow(missing_doc)];
// Initial glob-exports mean that all the contents of all the modules
// wind up exported, if you're interested in writing platform-specific code.
#[cfg(not(test))]
#[lang="log_type"]
+#[allow(missing_doc)]
pub fn log_type<T>(level: u32, object: &T) {
use cast;
use container::Container;
pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;
pub static RC_IMMORTAL : uint = 0x77777777;
+ #[allow(missing_doc)]
pub struct BoxHeaderRepr {
ref_count: uint,
type_desc: *TyDesc,
next: *BoxRepr,
}
+ #[allow(missing_doc)]
pub struct BoxRepr {
header: BoxHeaderRepr,
data: u8
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[allow(missing_doc)];
+
// function names are almost identical to C's libmath, a few have been
// renamed, grep for "rename:"
// except according to those terms.
//! Operations and constants for `f32`
+#[allow(missing_doc)];
use libc::c_int;
use num::{Zero, One, strconv};
//! Operations and constants for `f64`
+#[allow(missing_doc)];
+
use libc::c_int;
use num::{Zero, One, strconv};
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
// PORT this must match in width according to architecture
+#[allow(missing_doc)];
+
use f64;
use libc::c_int;
use num::{Zero, One, strconv};
pub static min_value: $T = (-1 as $T) << (bits - 1);
pub static max_value: $T = min_value - 1 as $T;
+/// Calculates the sum of two numbers
#[inline(always)]
pub fn add(x: $T, y: $T) -> $T { x + y }
+/// Subtracts the second number from the first
#[inline(always)]
pub fn sub(x: $T, y: $T) -> $T { x - y }
+/// Multiplies two numbers together
#[inline(always)]
pub fn mul(x: $T, y: $T) -> $T { x * y }
+/// Divides the first argument by the second argument (using integer division)
+/// Divides the first argument by the second argument (using integer division)
#[inline(always)]
pub fn div(x: $T, y: $T) -> $T { x / y }
#[inline(always)]
pub fn rem(x: $T, y: $T) -> $T { x % y }
+/// Returns true iff `x < y`
#[inline(always)]
pub fn lt(x: $T, y: $T) -> bool { x < y }
+/// Returns true iff `x <= y`
#[inline(always)]
pub fn le(x: $T, y: $T) -> bool { x <= y }
+/// Returns true iff `x == y`
#[inline(always)]
pub fn eq(x: $T, y: $T) -> bool { x == y }
+/// Returns true iff `x != y`
#[inline(always)]
pub fn ne(x: $T, y: $T) -> bool { x != y }
+/// Returns true iff `x >= y`
#[inline(always)]
pub fn ge(x: $T, y: $T) -> bool { x >= y }
+/// Returns true iff `x > y`
#[inline(always)]
pub fn gt(x: $T, y: $T) -> bool { x > y }
// except according to those terms.
//! An interface for numeric types
+
+#[allow(missing_doc)];
+
use cmp::{Eq, ApproxEq, Ord};
use ops::{Add, Sub, Mul, Div, Rem, Neg};
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[allow(missing_doc)];
+
use container::Container;
use core::cmp::{Ord, Eq};
use ops::{Add, Sub, Mul, Div, Rem, Neg};
pub static min_value: $T = 0 as $T;
pub static max_value: $T = 0 as $T - 1 as $T;
+/// Calculates the sum of two numbers
#[inline(always)]
pub fn add(x: $T, y: $T) -> $T { x + y }
+/// Subtracts the second number from the first
#[inline(always)]
pub fn sub(x: $T, y: $T) -> $T { x - y }
+/// Multiplies two numbers together
#[inline(always)]
pub fn mul(x: $T, y: $T) -> $T { x * y }
+/// Divides the first argument by the second argument (using integer division)
#[inline(always)]
pub fn div(x: $T, y: $T) -> $T { x / y }
+/// Calculates the integer remainder when x is divided by y (equivalent to the
+/// '%' operator)
#[inline(always)]
pub fn rem(x: $T, y: $T) -> $T { x % y }
+/// Returns true iff `x < y`
#[inline(always)]
pub fn lt(x: $T, y: $T) -> bool { x < y }
+/// Returns true iff `x <= y`
#[inline(always)]
pub fn le(x: $T, y: $T) -> bool { x <= y }
+/// Returns true iff `x == y`
#[inline(always)]
pub fn eq(x: $T, y: $T) -> bool { x == y }
+/// Returns true iff `x != y`
#[inline(always)]
pub fn ne(x: $T, y: $T) -> bool { x != y }
+/// Returns true iff `x >= y`
#[inline(always)]
pub fn ge(x: $T, y: $T) -> bool { x >= y }
+/// Returns true iff `x > y`
#[inline(always)]
pub fn gt(x: $T, y: $T) -> bool { x > y }
*/
+#[allow(missing_doc)];
+
use cmp::{Eq, Ord};
use kinds::Copy;
use option::{None, Option, Some};
//! Traits for the built-in operators
+#[allow(missing_doc)];
+
#[lang="drop"]
pub trait Drop {
fn finalize(&self); // FIXME(#4332): Rename to "drop"? --pcwalton
* to write OS-ignorant code by default.
*/
+#[allow(missing_doc)];
+
use cast;
use io;
use libc;
pub use libc::fclose;
pub use os::consts::*;
+/// Delegates to the libc close() function, returning the same return value.
pub fn close(fd: c_int) -> c_int {
unsafe {
libc::close(fd)
}
}
+/// Returns a vector of (variable, value) pairs for all the environment
+/// variables of the current process.
pub fn env() -> ~[(~str,~str)] {
unsafe {
#[cfg(windows)]
}
#[cfg(unix)]
+/// Fetches the environment variable `n` from the current process, returning
+/// None if the variable isn't set.
pub fn getenv(n: &str) -> Option<~str> {
unsafe {
do with_env_lock {
}
#[cfg(windows)]
+/// Fetches the environment variable `n` from the current process, returning
+/// None if the variable isn't set.
pub fn getenv(n: &str) -> Option<~str> {
unsafe {
do with_env_lock {
#[cfg(unix)]
+/// Sets the environment variable `n` to the value `v` for the currently running
+/// process
pub fn setenv(n: &str, v: &str) {
unsafe {
do with_env_lock {
#[cfg(windows)]
+/// Sets the environment variable `n` to the value `v` for the currently running
+/// process
pub fn setenv(n: &str, v: &str) {
unsafe {
do with_env_lock {
}
}
-
+/// Returns the proper dll filename for the given basename of a file.
pub fn dll_filename(base: &str) -> ~str {
return str::to_owned(DLL_PREFIX) + str::to_owned(base) +
str::to_owned(DLL_SUFFIX)
}
-
+/// Optionally returns the filesystem path to the current executable which is
+/// running. If any failure occurs, None is returned.
pub fn self_exe_path() -> Option<Path> {
#[cfg(target_os = "freebsd")]
}
}
+/// Changes the current working directory to the specified path, returning
+/// whether the change was completed successfully or not.
pub fn change_dir(p: &Path) -> bool {
return chdir(p);
}
#[cfg(unix)]
+/// Returns the platform-specific value of errno
pub fn errno() -> int {
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
}
#[cfg(windows)]
+/// Returns the platform-specific value of errno
pub fn errno() -> uint {
use libc::types::os::arch::extra::DWORD;
fn overridden_arg_key(_v: @OverriddenArgs) {}
+/// Returns the arguments which this program was started with (normally passed
+/// via the command line).
+///
+/// The return value of the function can be changed by invoking the
+/// `os::set_args` function.
pub fn args() -> ~[~str] {
unsafe {
match local_data::local_data_get(overridden_arg_key) {
}
}
+/// For the current task, overrides the task-local cache of the arguments this
+/// program had when it started. These new arguments are only available to the
+/// current task via the `os::args` method.
pub fn set_args(new_args: ~[~str]) {
unsafe {
let overridden_args = @OverriddenArgs { val: copy new_args };
*/
+#[allow(missing_doc)];
+
use container::Container;
use cmp::Eq;
use libc;
*/
+#[allow(missing_doc)];
+
use container::Container;
use cast::{forget, transmute, transmute_copy};
use either::{Either, Left, Right};
memmove64(dst as *mut u8, src as *u8, n as u64);
}
+/**
+ * Copies data from one location to another
+ *
+ * Copies `count` elements (not bytes) from `src` to `dst`. The source
+ * and destination may overlap.
+ */
#[inline(always)]
#[cfg(target_word_size = "64", not(stage0))]
pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
memmove32(dst as *mut u8, src as *u8, n as u32);
}
+/**
+ * Copies data from one location to another. This uses memcpy instead of memmove
+ * to take advantage of the knowledge that the memory does not overlap.
+ *
+ * Copies `count` elements (not bytes) from `src` to `dst`. The source
+ * and destination may overlap.
+ */
#[inline(always)]
#[cfg(target_word_size = "32", not(stage0))]
pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: uint) {
memmove64(dst as *mut u8, src as *u8, n as u64);
}
+/**
+ * Copies data from one location to another. This uses memcpy instead of memmove
+ * to take advantage of the knowledge that the memory does not overlap.
+ *
+ * Copies `count` elements (not bytes) from `src` to `dst`. The source
+ * and destination may overlap.
+ */
#[inline(always)]
#[cfg(target_word_size = "64", not(stage0))]
pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: uint) {
libc_::memset(dst as *mut c_void, c as libc::c_int, n as size_t);
}
+/**
+ * Invokes memset on the specified pointer, setting `count` bytes of memory
+ * starting at `dst` to `c`.
+ */
#[inline(always)]
#[cfg(target_word_size = "32", not(stage0))]
pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
memset32(dst, c, count as u32);
}
+/**
+ * Invokes memset on the specified pointer, setting `count` bytes of memory
+ * starting at `dst` to `c`.
+ */
#[inline(always)]
#[cfg(target_word_size = "64", not(stage0))]
pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
array_each_with_len(arr, len, cb);
}
+#[allow(missing_doc)]
pub trait Ptr<T> {
fn is_null(&const self) -> bool;
fn is_not_null(&const self) -> bool;
/// A type that can be randomly generated using an Rng
pub trait Rand {
+ /// Generates a random instance of this type using the specified source of
+ /// randomness
fn rand<R: Rng>(rng: &mut R) -> Self;
}
/// A value with a particular weight compared to other values
pub struct Weighted<T> {
+ /// The numerical weight of this item
weight: uint,
+ /// The actual item which is being weighted
item: T,
}
+/// Helper functions attached to the Rng type
pub trait RngUtil {
/// Return a random value of a Rand type
fn gen<T:Rand>(&mut self) -> T;
*/
+#[allow(missing_doc)];
+
use intrinsic::{TyDesc, TyVisitor};
use intrinsic::Opaque;
use libc::c_void;
*/
+#[allow(missing_doc)];
+
use cast::transmute;
use char;
use intrinsic;
}
#[inline(always)]
+#[allow(missing_doc)]
pub fn map_opt<T,U:Copy,V:Copy>(
o_t: &Option<T>, op: &fn(&T) -> Result<V,U>) -> Result<Option<V>,U> {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[allow(missing_doc)];
+
use cast::transmute;
use unstable::intrinsics;
return unsafe { raw::from_bytes_with_null(vv) };
}
+/**
+ * Converts a vector to a string slice without performing any allocations.
+ *
+ * Once the slice has been validated as utf-8, it is transmuted in-place and
+ * returned as a '&str' instead of a '&[u8]'
+ *
+ * # Failure
+ *
+ * Fails if invalid UTF-8
+ */
pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
unsafe {
assert!(is_utf8(vector));
return true;
}
+/**
+ * Splits the string `s` based on `sep`, yielding all splits to the iterator
+ * function provide
+ *
+ * # Example
+ *
+ * ~~~ {.rust}
+ * let mut v = ~[];
+ * for each_split_str(".XXX.YYY.", ".") |subs| { v.push(subs); }
+ * assert!(v == ["XXX", "YYY"]);
+ * ~~~
+ */
pub fn each_split_str_nonempty<'a,'b>(s: &'a str,
sep: &'b str,
it: &fn(&'a str) -> bool) -> bool {
* Fails during iteration if the string contains a non-whitespace
* sequence longer than the limit.
*/
-pub fn _each_split_within<'a>(ss: &'a str,
+pub fn each_split_within<'a>(ss: &'a str,
lim: uint,
it: &fn(&'a str) -> bool) -> bool {
// Just for fun, let's write this as an state machine:
return cont;
}
-pub fn each_split_within<'a>(ss: &'a str,
- lim: uint,
- it: &fn(&'a str) -> bool) -> bool {
- _each_split_within(ss, lim, it)
-}
-
/**
* Replace all occurrences of one string with another
*
each_chari_reverse(s, |_, c| it(c))
}
-// Iterates over the chars in a string in reverse, with indices
+/// Iterates over the chars in a string in reverse, with indices
#[inline(always)]
pub fn each_chari_reverse(s: &str, it: &fn(uint, char) -> bool) -> bool {
let mut pos = s.len();
u
}
+/// Iterates over the utf-16 characters in the specified slice, yielding each
+/// decoded unicode character to the function provided.
+///
+/// # Failures
+///
+/// * Fails on invalid utf-16 data
pub fn utf16_chars(v: &[u16], f: &fn(char)) {
let len = v.len();
let mut i = 0u;
}
}
+/**
+ * Allocates a new string from the utf-16 slice provided
+ */
pub fn from_utf16(v: &[u16]) -> ~str {
let mut buf = ~"";
reserve(&mut buf, v.len());
buf
}
+/**
+ * Allocates a new string with the specified capacity. The string returned is
+ * the empty string, but has capacity for much more.
+ */
pub fn with_capacity(capacity: uint) -> ~str {
let mut buf = ~"";
reserve(&mut buf, capacity);
return char_range_at(s, i).ch;
}
+#[allow(missing_doc)]
pub struct CharRange {
ch: char,
next: uint
#[cfg(test)]
pub mod traits {}
+#[allow(missing_doc)]
pub trait StrSlice<'self> {
fn all(&self, it: &fn(char) -> bool) -> bool;
fn any(&self, it: &fn(char) -> bool) -> bool;
fn to_bytes(&self) -> ~[u8] { to_bytes(*self) }
}
+#[allow(missing_doc)]
pub trait OwnedStr {
fn push_str(&mut self, v: &str);
fn push_char(&mut self, c: char);
}
}
+/// External iterator for a string's characters. Use with the `std::iterator`
+/// module.
pub struct StrCharIterator<'self> {
priv index: uint,
priv string: &'self str,
//! Misc low level stuff
+#[allow(missing_doc)];
+
use option::{Some, None};
use cast;
use cmp::{Eq, Ord};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[allow(missing_doc)];
+
use cast;
use cmp::Eq;
use libc;
* ~~~
*/
+#[allow(missing_doc)];
+
use prelude::*;
use cast;
}
}
+/// A trait for converting a value to a list of bytes.
pub trait ToBytes {
+ /// Converts the current value to a list of bytes. This is equivalent to
+ /// invoking iter_bytes on a type and collecting all yielded values in an
+ /// array
fn to_bytes(&self, lsb0: bool) -> ~[u8];
}
use cmp::Eq;
use old_iter::BaseIter;
+/// A generic trait for converting a value to a string
pub trait ToStr {
+ /// Converts the value of `self` to an owned string
fn to_str(&self) -> ~str;
}
/// Trait for converting a type to a string, consuming it in the process.
pub trait ToStrConsume {
- // Cosume and convert to a string.
+ /// Cosume and convert to a string.
fn to_str_consume(self) -> ~str;
}
Nothing
}
+#[allow(missing_doc)]
pub struct TrieMap<T> {
priv root: TrieNode<T>,
priv length: uint
}
}
+#[allow(missing_doc)]
pub struct TrieSet {
priv map: TrieMap<()>
}
//! Operations on tuples
+#[allow(missing_doc)];
+
use kinds::Copy;
use vec;
pub use self::inner::*;
+/// Method extensions to pairs where both types satisfy the `Copy` bound
pub trait CopyableTuple<T, U> {
+ /// Return the first element of self
fn first(&self) -> T;
+ /// Return the second element of self
fn second(&self) -> U;
+ /// Return the results of swapping the two elements of self
fn swap(&self) -> (U, T);
}
}
}
+/// Method extensions for pairs where the types don't necessarily satisfy the
+/// `Copy` bound
pub trait ImmutableTuple<T, U> {
+ /// Return a reference to the first element of self
fn first_ref<'a>(&'a self) -> &'a T;
+ /// Return a reference to the second element of self
fn second_ref<'a>(&'a self) -> &'a U;
}
// The following code was generated by "src/etc/unicode.py"
+#[allow(missing_doc)];
+
pub mod general_category {
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
/// A non-copyable dummy type.
pub struct NonCopyable {
- i: (),
+ priv i: (),
}
impl Drop for NonCopyable {
fn finalize(&self) { }
}
+/// Creates a dummy non-copyable structure and returns it for use.
pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } }
}
// A botch to tide us over until core and std are fully demuted.
+#[allow(missing_doc)]
pub fn uniq_len<T>(v: &const ~[T]) -> uint {
unsafe {
let v: &~[T] = transmute(v);
v.pop()
}
+/// Consumes all elements, in a vector, moving them out into the / closure
+/// provided. The vector is traversed from the start to the end.
+///
+/// This method does not impose any requirements on the type of the vector being
+/// consumed, but it prevents any usage of the vector after this function is
+/// called.
+///
+/// # Examples
+///
+/// ~~~ {.rust}
+/// let v = ~[~"a", ~"b"];
+/// do vec::consume(v) |i, s| {
+/// // s has type ~str, not &~str
+/// io::println(s + fmt!(" %d", i));
+/// }
+/// ~~~
pub fn consume<T>(mut v: ~[T], f: &fn(uint, v: T)) {
unsafe {
do as_mut_buf(v) |p, ln| {
}
}
+/// Consumes all elements, in a vector, moving them out into the / closure
+/// provided. The vectors is traversed in reverse order (from end to start).
+///
+/// This method does not impose any requirements on the type of the vector being
+/// consumed, but it prevents any usage of the vector after this function is
+/// called.
pub fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T)) {
unsafe {
do as_mut_buf(v) |p, ln| {
unsafe { push_fast(v, initval) }
}
+/// Iterates over the slice `rhs`, copies each element, and then appends it to
+/// the vector provided `v`. The `rhs` vector is traversed in-order.
+///
+/// # Example
+///
+/// ~~~ {.rust}
+/// let mut a = ~[1];
+/// vec::push_all(&mut a, [2, 3, 4]);
+/// assert!(a == ~[1, 2, 3, 4]);
+/// ~~~
#[inline(always)]
pub fn push_all<T:Copy>(v: &mut ~[T], rhs: &const [T]) {
let new_len = v.len() + rhs.len();
}
}
+/// Takes ownership of the vector `rhs`, moving all elements into the specified
+/// vector `v`. This does not copy any elements, and it is illegal to use the
+/// `rhs` vector after calling this method (because it is moved here).
+///
+/// # Example
+///
+/// ~~~ {.rust}
+/// let mut a = ~[~1];
+/// vec::push_all_move(&mut a, ~[~2, ~3, ~4]);
+/// assert!(a == ~[~1, ~2, ~3, ~4]);
+/// ~~~
#[inline(always)]
pub fn push_all_move<T>(v: &mut ~[T], mut rhs: ~[T]) {
let new_len = v.len() + rhs.len();
}
// Appending
+
+/// Iterates over the `rhs` vector, copying each element and appending it to the
+/// `lhs`. Afterwards, the `lhs` is then returned for use again.
#[inline(always)]
pub fn append<T:Copy>(lhs: ~[T], rhs: &const [T]) -> ~[T] {
let mut v = lhs;
v
}
+/// Appends one element to the vector provided. The vector itself is then
+/// returned for use again.
#[inline(always)]
pub fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
let mut v = lhs;
result
}
+/// Consumes a vector, mapping it into a different vector. This function takes
+/// ownership of the supplied vector `v`, moving each element into the closure
+/// provided to generate a new element. The vector of new elements is then
+/// returned.
+///
+/// The original vector `v` cannot be used after this function call (it is moved
+/// inside), but there are no restrictions on the type of the vector.
pub fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U] {
let mut result = ~[];
do consume(v) |_i, x| {
* ~~~
*/
#[inline(always)]
-pub fn _each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
- // ^^^^
+pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
+ // ^^^^
// NB---this CANNOT be &const [T]! The reason
// is that you are passing it to `f()` using
// an immutable.
return true;
}
-pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool { _each(v, f) }
-
/// Like `each()`, but for the case where you have
/// a vector with mutable contents and you would like
/// to mutate the contents as you iterate.
#[inline(always)]
-pub fn _each_mut<'r,T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) -> bool {
+pub fn each_mut<'r,T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) -> bool {
let mut broke = false;
do as_mut_buf(v) |p, n| {
let mut n = n;
return broke;
}
-pub fn each_mut<'r,T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) -> bool {
- _each_mut(v, f)
-}
-
/// Like `each()`, but for the case where you have a vector that *may or may
/// not* have mutable contents.
#[inline(always)]
-pub fn _each_const<T>(v: &const [T], f: &fn(elem: &const T) -> bool) -> bool {
+pub fn each_const<T>(v: &const [T], f: &fn(elem: &const T) -> bool) -> bool {
let mut i = 0;
let n = v.len();
while i < n {
return true;
}
-pub fn each_const<t>(v: &const [t], f: &fn(elem: &const t) -> bool) -> bool {
- _each_const(v, f)
-}
-
/**
* Iterates over a vector's elements and indices
*
* Return true to continue, false to break.
*/
#[inline(always)]
-pub fn _eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool {
+pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool {
let mut i = 0;
for each(v) |p| {
if !f(i, p) { return false; }
return true;
}
-pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool {
- _eachi(v, f)
-}
-
/**
* Iterates over a mutable vector's elements and indices
*
* Return true to continue, false to break.
*/
#[inline(always)]
-pub fn _eachi_mut<'r,T>(v: &'r mut [T],
- f: &fn(uint, v: &'r mut T) -> bool) -> bool {
+pub fn eachi_mut<'r,T>(v: &'r mut [T],
+ f: &fn(uint, v: &'r mut T) -> bool) -> bool {
let mut i = 0;
for each_mut(v) |p| {
if !f(i, p) {
return true;
}
-pub fn eachi_mut<'r,T>(v: &'r mut [T],
- f: &fn(uint, v: &'r mut T) -> bool) -> bool {
- _eachi_mut(v, f)
-}
-
/**
* Iterates over a vector's elements in reverse
*
* Return true to continue, false to break.
*/
#[inline(always)]
-pub fn _each_reverse<'r,T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) -> bool {
- _eachi_reverse(v, |_i, v| blk(v))
-}
-
pub fn each_reverse<'r,T>(v: &'r [T], blk: &fn(v: &'r T) -> bool) -> bool {
- _each_reverse(v, blk)
+ eachi_reverse(v, |_i, v| blk(v))
}
/**
* Return true to continue, false to break.
*/
#[inline(always)]
-pub fn _eachi_reverse<'r,T>(v: &'r [T],
+pub fn eachi_reverse<'r,T>(v: &'r [T],
blk: &fn(i: uint, v: &'r T) -> bool) -> bool {
let mut i = v.len();
while i > 0 {
return true;
}
-pub fn eachi_reverse<'r,T>(v: &'r [T],
- blk: &fn(i: uint, v: &'r T) -> bool) -> bool {
- _eachi_reverse(v, blk)
-}
-
/**
* Iterates over two vectors simultaneously
*
* Both vectors must have the same length
*/
#[inline]
-pub fn _each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool {
+pub fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool {
assert_eq!(v1.len(), v2.len());
for uint::range(0u, v1.len()) |i| {
if !f(&v1[i], &v2[i]) {
return true;
}
-pub fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool {
- _each2(v1, v2, f)
-}
-
/**
*
* Iterates over two vector with mutable.
* Both vectors must have the same length
*/
#[inline]
-pub fn _each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T) -> bool) -> bool {
+pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T],
+ f: &fn(u: &mut U, t: &mut T) -> bool) -> bool {
assert_eq!(v1.len(), v2.len());
for uint::range(0u, v1.len()) |i| {
if !f(&mut v1[i], &mut v2[i]) {
return true;
}
-pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T) -> bool) -> bool {
- _each2_mut(v1, v2, f)
-}
-
/**
* Iterate over all permutations of vector `v`.
*
// Equality
+/// Tests whether two slices are equal to one another. This is only true if both
+/// slices are of the same length, and each of the corresponding elements return
+/// true when queried via the `eq` function.
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; }
true
}
+/// Similar to the `vec::eq` function, but this is defined for types which
+/// implement `TotalEq` as opposed to types which implement `Eq`. Equality
+/// comparisons are done via the `equals` function instead of `eq`.
fn equals<T: TotalEq>(a: &[T], b: &[T]) -> bool {
let (a_len, b_len) = (a.len(), b.len());
if a_len != b_len { return false; }
fn len(&const self) -> uint { len(*self) }
}
+#[allow(missing_doc)]
pub trait CopyableVector<T> {
fn to_owned(&self) -> ~[T];
}
}
}
+#[allow(missing_doc)]
pub trait ImmutableVector<'self, T> {
fn slice(&self, start: uint, end: uint) -> &'self [T];
fn iter(self) -> VecIterator<'self, T>;
}
}
+#[allow(missing_doc)]
pub trait ImmutableEqVector<T:Eq> {
fn position_elem(&self, t: &T) -> Option<uint>;
fn rposition_elem(&self, t: &T) -> Option<uint>;
}
}
+#[allow(missing_doc)]
pub trait ImmutableCopyableVector<T> {
fn filtered(&self, f: &fn(&T) -> bool) -> ~[T];
fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T>;
}
}
+#[allow(missing_doc)]
pub trait OwnedVector<T> {
fn push(&mut self, t: T);
fn push_all_move(&mut self, rhs: ~[T]);
fn clear(&mut self) { self.truncate(0) }
}
+#[allow(missing_doc)]
pub trait OwnedCopyableVector<T:Copy> {
fn push_all(&mut self, rhs: &const [T]);
fn grow(&mut self, n: uint, initval: &T);
}
}
+#[allow(missing_doc)]
trait OwnedEqVector<T:Eq> {
fn dedup(&mut self);
}
}
}
+#[allow(missing_doc)]
pub trait MutableVector<'self, T> {
fn mut_slice(self, start: uint, end: uint) -> &'self mut [T];
}
/// The internal 'unboxed' representation of a vector
+#[allow(missing_doc)]
pub struct UnboxedVecRepr {
fill: uint,
alloc: uint,
use util;
/// The internal representation of a (boxed) vector
+ #[allow(missing_doc)]
pub struct VecRepr {
box_header: managed::raw::BoxHeaderRepr,
unboxed: UnboxedVecRepr
}
+ /// The internal representation of a slice
pub struct SliceRepr {
+ /// Pointer to the base of this slice
data: *u8,
+ /// The length of the slice
len: uint
}
}
}
-// could be implemented with &[T] with .slice(), but this avoids bounds checks
+/// An external iterator for vectors (use with the std::iterator module)
pub struct VecIterator<'self, T> {
priv ptr: *T,
priv end: *T,
priv lifetime: &'self T // FIXME: #5922
}
+// could be implemented with &[T] with .slice(), but this avoids bounds checks
impl<'self, T> Iterator<&'self T> for VecIterator<'self, T> {
#[inline]
fn next(&mut self) -> Option<&'self T> {