This module is used for heap allocation.
A very simple way to allocate memory on the heap, provide ownership, and drop when out of scope.
- impl<T> Box<T>
- fn new(x:T) -> Box<T>: Allocates memory on the heap and places x into it
- impl <T> Box<T> where T: ?Sized
- unsafe fn from_raw(raw: *mut T) -> Box<T>: Constructs a box from a raw pointer. After creation, the pointer is owned by the new Box. It is unsafe for this very reason; the Box destructor will call the destructor of T and free the allocated memory. This may lead to double freeing that will cause a crash.
- fn into_raw(b: Box<T> -> *mut T: Consumes the box and returns the wrapped raw pointer.
- impl Box<Any + 'static>
- fn downcast<T>(self) -> Result<Box<T>, Box<Any + 'static>> where T:Any: Attempts to downcast the box to a concrete type.
- impl Box<Any + 'static + Send>
- fn downcast<T>(self) -> Result<Box<T>, Box<Any + ‘static + Send>> where T:Any: Attempts to downcast the box to a concrete type
Methods
Trait Implementations
- Impl <T> Default for Box<T> where T:Default
- fn default() -> Box<T>: Returns the default value for the type
- impl<T> Default for Box<[T]>
- fn default() -> Box<T>: Returns the default value for the type
- impl<T> Clone for Box<T> where T:Clone
- fn clone(&self) -> Box<T>: Returns a new box with a clone of the box's contents
- fn clone_from(&mut self, source: &Box<T>): Copies sources contents into self without creating a new allocation
- impl Clone for Box<str>
- fn clone(&self) -> Box<str>: Returns a copy of the value
- fn clone_from(&mut self, source: &Self): Performs a copy-assignment from source
- impl<T> PartialEq<Box<T>> for Box<T> where T:PartialEq<T> + ?Sized
- fn eq(&self, other: &Box<T>) -> bool: Test self and other to be equal. Used by ==
- fn ne(&self, other: &Box<T>) ->: Tests for inequality. Used by !=
- impl<T> PartialOrd<Box<T>> for Box<T> where T:PartialOrd<T> + ?Sized
- fn partial_cmp(&self, other: &Box<T>) -> Option<Ordering>: Returns an ordering between self and other values if it exists
- fn lt(&self, other: &Box<T>) -> bool: Tests whether self is less than other. Used by <
- fn le(&self, other: &Box<T>) -> bool: Tests whether self is less than or equal to other. Used by <=
- fn ge(&self, other: &Box<T>) -> bool: Tests whether self is greater than or equal to other. Used by >=
- Fn gt(&self, other: &Box<T>) -> bool: Tests whether self is greater than other. Used by >
- impl <T> Ord for Box<T> where T:Ord + ?Sized
- fn cmp(&self, other: &Box<T>) -> Ordering: Returns an ordering between self and other
- impl <T> Hash for Box<T> where T: Hash + ?Sized
- fn hash<H>(&self, state: &mut H) where H: Hasher: Feeds the value into the state and updates the hasher if required
- fn hash_slice<H>(data: &[Self], state &mut H) where H: Hasher: Feeds the slice of this type into the state
- impl<T> From<T> for Box<T>
- fn from(t: T) -> Box<T>: Performs a conversion
- impl<T> Display for Box<T> where T: Display + ?Sized
- fn fmt(&self, f: &mut Formatter) -> Result<(), Error>: Formats the value using the given formatter
- impl<T> Debug for Box<T> where T:Debug + ?Sized
- fn fmt(&self, f: &mut Formatter) -> Result<(), Error>: Formats the value using the given formatter
- impl<T> Pointer for Box<T> where T: ?Sized
- fn fmt(&self, f: &mut Formatter) -> Result<(), Error>: Formats the value using the given formatter
- impl<T> Deref for Box<T> where T: ?Sized
- fn deref(&self) -> &T: Dereference a value
- impl<T> DerefMut for Box<T> where T: ?Sized
- fn deref_mut(&mut self) -> &mut T: Mutably dereference a value
- impl<I> Iterator for Box<I> where I: Iterator + ?Sized
- fn next(&mut self) -> Option<I::Item>: Advances the iterator and returns the next value
- fn size_hint(&self) -> (usize, Option<usize>): Returns the bounds on the remaining length of the iterator
- fn count(self) -> usize: Returns the number of iterations
- fn last(self) -> Option<Self::Item>: Returns the last element
- fn nth(&mut self, n: usize) -> Option<Self::Item>: Consumes n elements of the iterator and returns the next one after that
- fn chain<U>(self, other: U) -> Chain<Self, U::Iterator> where U: IntoIterator <Item=Self::Item>: Takes two iterators and creates a new one over both in sequence
- fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter> where U: IntoIter: Zips two iterators into a single pair
- fn map<B, F>(self, f: F) -> Map<Self, F> where F: FnMut(Self::Item) -> B: Takes a closure and creates an iterator that calls that closure on each element
- fn filter<P>(self, predicate: P) -> Filter<Self, P> where P: FnMut(&Self::Item) -> bool: Creates an iterator that uses a closure to see if an element should be yielded
- Fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where F: FnMut(Self::Item) -> Option<B<: Creates an iterator that filters and maps
- fn enumerate(self) -> Enumerate<Self>: Creates an iterator that gives the current iteration count and the next value
- fn peekable(self) -> Peekable<Self>: Creates an iterator to peek at the next element of the iterator without consuming
- fn skip_while<P>(self, predicate: P)-> SkipWhile<Self, P> where P: FnMut(&Self::Item) -> bool: Creates an iterator that skips elements based on the predicate
- fn skip(self, n: usize) -> Skip<Self>: Creates an iterator that skips the first n elements
- fn take(self, n:usize) -> Take<Self>: Creates an iterator that yields the first n elements
- fn take_while<P>(self, predicate: P) -> TakeWhile<Self. P> where P:FnMut(&Self::Item) -> bool: Creates an iterator that yields elements based on the predicate
- fn scan<St, B, F>(self, init_state: St, f : F) -> Scan<Self, St, F> where F: FnMut(&mut St, Self::Item) -> Option<B>: An iterator adaptor similar to fold() that holds the internal state and produces a new iterator
- fn flat_map<U, F>(self f: F) -> FlatMap<Self, U, F> where F: FnMut(Self::Item) -> U, U:IntoIterator: Creates a flattened nested structure. Works like map.
- fn fuse(self) -> Fuse<Self>: Creates an iterator that ends after the first instance of None
- fn inspect<F>(self, f: F) -> Inspect<Self, F> where F:FnMut(&Self::Item) -> (): Does something with each element and passes the value on
- fn by_ref(&mut self) -> &mut Self: Borrow the iterator. Doesn’t consume it.
- fn collect<B>(self) -> B where B: FromIterator <Self::Item>: Changes the iterator to a collection
- fn partition<B, F>(self, f: F) -> (B, B) where B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool: Consumes an iterator, creating two collections from it
- fn fold<B, F>(self, init: B, f: F) -> B where F: FnMut(B, Self::Item) -> B: An iterator adaptor that applies a function, producing a single, final value
- fn all<F>(&mut self, f: F) -> bool where F: FnMut(Self::Item) -> bool: Tests if every element of the iterator matches a predicate
- fn any<F>(&mut self, f: F) -> bool where F: FnMut(Self::Item) -> bool: Tests if any element of the iterator matches a predicate
- fn find<P>(&mut self, predicate: P) -> Option<Self::Item> where P: FnMut(&Self::Item) -> bool: Searches for an element of an iterator that satisfies a predicate
- fn position<P>(&mut self, predicate: P) -> Option<usize> where P: FnMut(Self::Item) -> bool: Searches for an element in an iterator, returning its index
- fn rposition<P>(&mut self, predicate: P) -> Option<usize> where P: FnMut(Self::Item) -> bool, Self: ExactSizeIterator + DoubleEndedIterator: Searches for an element in an iterator from the right, returning its index
- fn max(self) -> Option<Self::Item> where Self::Item: Ord: Returns the maximum element of an iterator
- fn min(self) -> Option<Self::Item> where Self::Item: Ord: Returns the minimum element of an iterator
- fn max_by_key<B, F>(self, f: F) -> Option<Self::Item> where B: Ord, F: FnMut(&Self::Item) -> B: Returns the element that gives the maximum value from the specified function
- fn min_by_key<B, F>(self, f: F) -> Option<Self::Item> where B: Ord, F: FnMut(&Self::Item) -> B: Returns the element that gives the minimum value from the specified function
- fn rev(self) -> Rev<Self> where Self: DoubleEndedIterator: Reverses an iterator's direction
- fn unzip <A, B, FromA, FromB> (self) -> (FromA, FromB) where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Iterator<Item=(A, B)>: Converts an iterator of pairs into a pair of containers
- fn cloned<'a, T>(self) -> Cloned<Self> where Self: Iterator<Item=&'a T>, T: 'a + Clone: Creates an iterator that clones all of its elements
- fn cycle(self) -> Cycle<Self> where Self: Clone: Repeats an iterator endlessly
- fn sum<S>(self) -> S where S: Sum<Self::Item>: Sums the elements of an iterator
- fn product<P>(self) -> P where P: Product<Self::Item>: Iterates over the entire iterator, multiplying all the elements
- fn cmp<I>(self, other: I) -> Ordering where I: IntoIterator <Item=Self::Item>, Self::Item: Ord: Compares the elements of this Iterator with those of another
- fn partial_cmp<I>(self, other: I) -> Option<Ordering> where I: IntoIterator, Self::Item: PartialOrd<I::Item>: Compares the elements of this Iterator with those of another
- fn eq<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialEq<I::Item>: Determines if the elements of this Iterator are equal to those of another
- fn ne<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialEq<I::Item>: Determines if the elements of this Iterator are unequal to those of another
- fn lt<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item>: Determines if the elements of this Iterator are less than those of another
- fn le<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item>: Determines if the elements of this Iterator are less than or equal to those of another
- fn gt<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item>: Determines if the elements of this Iterator are greater than those of another
- fn ge<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item>: Determines if the elements of this Iterator are greater than or equal to those of another
- impl<I> DoubleEndedIterator for Box<I> where I: DoubleEndedIterator + ?Sized
- fn next_back(&mut self) -> Option<I::Item>: Removes and returns an element from the end of the iterator
- impl <T> ExactSizeIterator for Box<I> where I: ExactSizeIterator + ?Sized
- fn len(&self) -> usize: Returns the exact number of times the iterator will iterate.
- impl<T> Clone for Box<[T]> where T:Clone
- fn clone(&self) -> Box<[T]>: Returns a copy of the value
- fn clone_from(&mut self, source: &Self): Performs copy-assignment from source
- impl<T> Borrow<T> for Box<T> where T:?Sized
- fn borrow(&self) -> &T: Immutably borrows from an owned value
- impl<T> BorrowMut<T> for Box<T> where T:?Sized
- fn borrow_mut(&mut self) -> &mut T: Mutably borrows from an owned value
- impl<T> AsRef<T> for Box<T> where T:?Sized
- fn as_ref(&self) -> &T: Performs the conversion
- impl<T> AsMut for Box<T> where T:?Sized
- fn as_mut(&mut self) -> &mut T: Performs the conversion
- impl<’a, E: Error + ‘a> From<E> from Box<Error + ‘a>
- fn from(err: E) -> Box<Error + 'a>: Performs the conversion
- impl From<String> for Box<Error + Send + Sync>
- fn from(err: String) -> Box<Error + Send + Sync>: Performs the conversion
- impl From<’a, ‘b> From<&’b str> for Box<Error + Send + Sync + ‘a>
- fn from(err: &'b str) -> Box<Error + Send + Sync + 'a>: Performs the conversion
- impl<T: Error> Error for Box<T>
- fn description(&self) -> &str: Short description of the error
- fn cause(&self) -> Option<&Error>: Lower-level cause of this error, if any
- impl<R: Read + ?Sized> Read for Box<R>
- fn read(&mut self, buf: &mut [u8]) -> Result<usize>: Pulls some bytes from this source into the specified buffer, returning how many bytes were read
- fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>: Reads all bytes until EOF in this source, placing them into buf
- fn read_to_string(&mut self, buf: &mut String) -> Result<usize>: Reads all bytes until EOF in this source, placing them into buf
- fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>: Reads the exact number of bytes required to fill buf
- fn by_ref(&mut self) -> &mut Self where Self: Sized: Creates a by reference adaptor for this instance of Read
- fn bytes(self) -> Bytes<Self> where Self: Sized: Transforms this Read instance to an Iterator over its bytes
- fn chain<R: Read>(self, next: R) -> Chain<Self, R> where Self: Sized: Creates an adaptor that will chain this stream with another
- fn take(self, limit: u64) -> Take<Self> where Self: Sized: Creates an adaptor that will read at most limit bytes from it
- impl <W: Write + ?Sized> Write for Box<W>
- fn write(&mut self, buf: &[u8]) -> Result<usize>: Writes a buffer into this object, returning how many bytes were written
- fn flush(&mut self) -> Result<()>: Flushes this output stream, ensuring that all intermediately buffered contents reach their destination
- fn write_all(&mut self, buf: &[u8]) -> Result<()>: Attempts to write an entire buffer into this write
- fn write_fmt(&mut self, fmt: Arguments) -> Result<()>: Writes a formatted string into this writer, returning any error encountered
- fn by_ref(&mut self) -> &mut Self where Self: Sized: Creates a by reference adaptor for this instance of Write
- impl<S: Seek + ?Sized> Seek for Box<S>
- fn seek(&mut self, pos: SeekFrom) -> Result<u64>: Seeks to an offset, in bytes, in a stream
- impl<B: BufRead + ?Sized> BufRead for Box<B>
- fn fill_buf(&mut self) -> Result<&[u8]>: Fills the internal buffer of this object, returning the buffer contents
- fn consume(&mut self, amt: usize): Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to be read
- fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize>: Reads all bytes into buf until the delimiter byte is reached
- fn read_line(&mut self, buf: &mut String) -> Result<usize>: Reads all bytes until a newline (the 0 x A byte) is reached, and appends them to the provided buffer
- fn split(self, byte: u8) -> Split<Self> where Self: Sized: Returns an iterator over the contents of this reader split on the byte byte
- fn lines(self) -> Lines<Self> where Self: Sized: Returns an iterator over the lines of this reader