Variable sized arrays / Vectors
let mut vec: Vec<T> = Vec::new();
= Vec::with_capacity();
= vec![];
= boxedarray.into_vec()
= Vec::from(slice|str|VecDeque|CString)
= othervec.clone();
if T:Clone


Accessing
vec[3];
vec[1..3], vec[..3], vec[3..], vec[..]; vec[2] = a;
vec.len();
.is_empty();
.first_mut(); .last_mut();
-> Option
.get_mut(index);
-> Option
.contains(needle);
-> bool
.iter().find(|&T| -> bool);
-> Option
.binary_search(x:&T);
-> Result<usize, usize>
Ok(i): pos, Err(i): pos for insertion
.binary_search_by(|&T|->Ordering);
.binary_search_by_key(Key, |&T|->Key);
.ends_with(needle);
.starts_with(needle);


Adding
.push(3);
to end
.insert(index, element);
.extend(iterable);
.extend_from_slice(&[T]);
.append(other : Vec);
drains other
.clone_from(&Vec<T>);
overrides self, if T:Clone
.clone_from_slice(&[T]);
if T:Clone
.copy_from_slice(&[T]);
if T:Copy (use memcpy)


Removing
.pop();
removes last -> Option
.remove(index);
-> el, shifts left
.swap_remove(index);
-> el, fills with last
.truncate(i);
cut until .len() = i
.drain(range);
-> iter that drains
.clear();
.retain(|i| -> bool);
in place
.dedup();
removes duplicates (if T:PartialEq)


Manipulating
.sort();
in place
.sort_by(|&T|->Ordering);
in place
.sort_by_key(|&T|->Key);
Key:Ordering
.reverse();
in place
.swap(index1, index2);


Transforming (Iter, as_, to_)
.iter_mut();
->&mut T, keeps vector
.into_iter();
->T, consumes vector
.chunks_mut(cnk_sz);
-> iter over a non overlapping slice at a time
.windows(wnd_sz);
-> iter over an overlapping slice at a time


.into_boxed_slice();
-> Box<T>
.as_ref();
-> &[T] or &Vec<T>
.to_vec();
like clone(), if T:Clone
.as_mut_slice();
-> &mut[T]


Memory
.capacity();
.reserve(100);
in addition to .len() or more
.reserve_exact(100);
in addition to .len()
.shrink_to_fit();


Split
.split_at_mut(mid);
-> (p1, p2), [mid] in 2nd part
.split_mut(|&T| -> bool);
.splitn_mut(n, |&T| -> bool); .rsplitn_mut(_);
-> iter over mutable subslices,
seperated by ||->true, at most n times
.split_off(mid);
-> Vec; [mid] in 2nd part


Comparision
.cmp() .eq() .ne();
T: PartialEq
.lt() .le() .gt() .ge();
if T:PartialOrd


.hash(state: Hasher)
if T:Hash


Traits
From<BinaryHeap> from() | BorrowMut borrow /_mut() | Clone clone/_from() | Hash hash/_slice() | IndexMut index/_mut() DerefMut deref/_mut() | FromIterator from_iter() | IntoIterator into_iter() | Extend extend() | PartialEq eq() ne() | PartialOrd partial_cmp() lt() le() gt() ge() | Eq | Ord cmp() | Drop drop() | Default default() | Debug (if T:Debug) fmt() | AsRef AsMut as_ref() as_mut() | From from() | Write write() write_all() flush() by_ref() .. |
Hashmaps / Dicts
use std::collections::HashMap;
let mut foo: HashMap<K, V> = HashMap::new();
= HashMap::with_capacity();
K: Eq, Hash
= other.clone();
if V,K:Clone


Access
foo[key];
foo.len();
.iter_mut();
-> iter over (&K, &mut V)
.into_iter();
-> IterMut
.keys();
-> iter over keys
.values_mut();
-> iter over values
.is_empty();
-> bool
.contains_key(k:Q);
-> bool


Manipulate
.get_mut(k:&Q);
-> Option<&V>, K:Borrow<Q>
.entry(key);
in place manipulation
.drain();
-> iter that drains
.clear();
.extend(iter : <Item=(&K,&V)>);
.insert(k,v);
-> Option<&V>, None on success.
.remove(k:&Q);
-> Option<&V>
.from_iter(iter : <Item=(K,V)>);
-> HashMap


Manage
.capacity();
.reserve(additional);
.shrink_to_fit();
.clone_from(source);
overrides self


Comparision
.eq() .ne();
T: PartialEq


Special Hasher
let hm = HashMap::with_hasher(b);
= HashMap::with_capacity_and_hasher(b);
hm.hasher(b);
-> &BuildHasher


Traits
Clone clone() clone_from() | PartialEq eq() ne() | Eq | Debug fmt() | Default default() | Index index() | IntoIterator into_iter() | FromIterator from_iter() | Extend extend() |
Option
let foo : Option = Some(T::new());
= None;


If
.is_some();
.is_none();


&
.as_ref();
-> Option<&T>
.as_mut();
-> Option<&mut T>
.cloned();
Option<&T> -> Option<T> if T:Clone
.iter_mut();
Iter with 1 or 0 elements


Retrieve T
.unwrap();
-> T or panic
.expect(msg);
-> T or panic(msg)
.unwrap_or(default:T);
-> T
.unwrap_or_default();
-> T, if T:Default
.unwrap_or_else(|| -> T);
-> T
mutableopt.take();
-> Option<T>, moves T out of mutableopt


Manipulate (map)
.map(|t| -> U);
-> Option<U>
.map_or(default:U, |t| -> U);
-> Option<U>
.map_or_else(|| default -> U, |t| -> U);
-> Option<U>


to Result<>
.ok_or(err:E);
-> Result<T,E>
.ok_or_else(|| err -> E);
-> Result<T,E>


Boolean Combinations
a.and(b : Option<U>);
b if a && b
a.and_then(|| b -> Option<U>);
b if a && b
a.or(b : Option<T>);
a if a else b
a.or_else(|| b -> Option<T>);
a if a else b


Traits
Hash hash() | Debug fmt() | Ord cmp() | Eq | PartialOrd partial_cmp() lt() le() gt() ge() | PartialEq eq() ne() | Copy | Clone clone() clone_from() | Default default() | IntoIterator into_iter() | FromIterator from_iter() |
Result
let foo : Result = Ok(T::new());
= Err(E::new());


If
.is_ok();
.is_err();


&
.as_ref();
-> Result<&T, &E>
.as_mut();
-> Option<&mut T, &mut E>
.iter_mut();
Iter with 1 or 0 elements


Retrieve T
.unwrap();
-> T or panic; if E:Debug
.expect(msg);
-> T or panic(msg); if E:Debug
.unwrap_or(default:T);
-> T
.unwrap_or_else(|err| default -> T);
-> T


Retrieve E
.unwrap_err();
-> E; if T:Debug


Manipulate (map)
.map(|t| -> U);
-> Result<U,E>
.map_err(|e| -> F);
-> Result<T,F>


to Option<>
.ok();
-> Option<T>
.err();
-> Option<E>


Boolean Combinations
a.and(b : Result<U,E>);
b if a && b else first err
a.and_then(|| b -> Result<U,E>);
b if a && b else first error
a.or(b : Result<T,E>);
a if a else b
a.or_else(|| b -> Result<T,E>);
a if a else b


Traits
Hash hash() | Debug fmt() | Ord cmp() | Eq | PartialOrd partial_cmp() lt() le() gt() ge() | PartialEq eq() ne() | Copy | Clone clone() clone_from() | IntoIterator into_iter() | FromIterator from_iter() |
Rust Cheatsheet

Contribute at github.com/phaiax/rust-cheatsheet

Creative Commons License
This work is licensed under a
Creative Commons Attribution-
ShareAlike 4.0 International License
.

A contiguous growable array type, written Vec<T> but pronounced 'vector.'

Examples

fn main() { let mut vec = Vec::new(); vec.push(1); vec.push(2); assert_eq!(vec.len(), 2); assert_eq!(vec[0], 1); assert_eq!(vec.pop(), Some(2)); assert_eq!(vec.len(), 1); vec[0] = 7; assert_eq!(vec[0], 7); vec.extend([1, 2, 3].iter().cloned()); for x in &vec { println!("{}", x); } assert_eq!(vec, [7, 1, 2, 3]); }
let mut vec = Vec::new();
vec.push(1);
vec.push(2);

assert_eq!(vec.len(), 2);
assert_eq!(vec[0], 1);

assert_eq!(vec.pop(), Some(2));
assert_eq!(vec.len(), 1);

vec[0] = 7;
assert_eq!(vec[0], 7);

vec.extend([1, 2, 3].iter().cloned());

for x in &vec {
    println!("{}", x);
}
assert_eq!(vec, [7, 1, 2, 3]);

The vec! macro is provided to make initialization more convenient:

fn main() { let mut vec = vec![1, 2, 3]; vec.push(4); assert_eq!(vec, [1, 2, 3, 4]); }
let mut vec = vec![1, 2, 3];
vec.push(4);
assert_eq!(vec, [1, 2, 3, 4]);

It can also initialize each element of a Vec<T> with a given value:

fn main() { let vec = vec![0; 5]; assert_eq!(vec, [0, 0, 0, 0, 0]); }
let vec = vec![0; 5];
assert_eq!(vec, [0, 0, 0, 0, 0]);

Use a Vec<T> as an efficient stack:

fn main() { let mut stack = Vec::new(); stack.push(1); stack.push(2); stack.push(3); while let Some(top) = stack.pop() { // Prints 3, 2, 1 println!("{}", top); } }
let mut stack = Vec::new();

stack.push(1);
stack.push(2);
stack.push(3);

while let Some(top) = stack.pop() {
    // Prints 3, 2, 1
    println!("{}", top);
}

Indexing

The Vec type allows to access values by index, because it implements the Index trait. An example will be more explicit:

fn main() { let v = vec!(0, 2, 4, 6); println!("{}", v[1]); // it will display '2' }
let v = vec!(0, 2, 4, 6);
println!("{}", v[1]); // it will display '2'

However be careful: if you try to access an index which isn't in the Vec, your software will panic! You cannot do this:

fn main() { let v = vec!(0, 2, 4, 6); println!("{}", v[6]); // it will panic! }
let v = vec!(0, 2, 4, 6);
println!("{}", v[6]); // it will panic!

In conclusion: always check if the index you want to get really exists before doing it.

Slicing

A Vec can be mutable. Slices, on the other hand, are read-only objects. To get a slice, use "&". Example:

fn main() { fn read_slice(slice: &[usize]) { // ... } let v = vec!(0, 1); read_slice(&v); // ... and that's all! // you can also do it like this: let x : &[usize] = &v; }
fn read_slice(slice: &[usize]) {
    // ...
}

let v = vec!(0, 1);
read_slice(&v);

// ... and that's all!
// you can also do it like this:
let x : &[usize] = &v;

In Rust, it's more common to pass slices as arguments rather than vectors when you just want to provide a read access. The same goes for String and &str.

Capacity and reallocation

The capacity of a vector is the amount of space allocated for any future elements that will be added onto the vector. This is not to be confused with the length of a vector, which specifies the number of actual elements within the vector. If a vector's length exceeds its capacity, its capacity will automatically be increased, but its elements will have to be reallocated.

For example, a vector with capacity 10 and length 0 would be an empty vector with space for 10 more elements. Pushing 10 or fewer elements onto the vector will not change its capacity or cause reallocation to occur. However, if the vector's length is increased to 11, it will have to reallocate, which can be slow. For this reason, it is recommended to use Vec::with_capacity whenever possible to specify how big the vector is expected to get.

Guarantees

Due to its incredibly fundamental nature, Vec makes a lot of guarantees about its design. This ensures that it's as low-overhead as possible in the general case, and can be correctly manipulated in primitive ways by unsafe code. Note that these guarantees refer to an unqualified Vec<T>. If additional type parameters are added (e.g. to support custom allocators), overriding their defaults may change the behavior.

Most fundamentally, Vec is and always will be a (pointer, capacity, length) triplet. No more, no less. The order of these fields is completely unspecified, and you should use the appropriate methods to modify these. The pointer will never be null, so this type is null-pointer-optimized.

However, the pointer may not actually point to allocated memory. In particular, if you construct a Vec with capacity 0 via Vec::new(), vec![], Vec::with_capacity(0), or by calling shrink_to_fit() on an empty Vec, it will not allocate memory. Similarly, if you store zero-sized types inside a Vec, it will not allocate space for them. Note that in this case the Vec may not report a capacity() of 0. Vec will allocate if and only if mem::size_of::<T>() * capacity() > 0. In general, Vec's allocation details are subtle enough that it is strongly recommended that you only free memory allocated by a Vec by creating a new Vec and dropping it.

If a Vec has allocated memory, then the memory it points to is on the heap (as defined by the allocator Rust is configured to use by default), and its pointer points to len() initialized elements in order (what you would see if you coerced it to a slice), followed by capacity() - len() logically uninitialized elements.

Vec will never perform a "small optimization" where elements are actually stored on the stack for two reasons:

  • It would make it more difficult for unsafe code to correctly manipulate a Vec. The contents of a Vec wouldn't have a stable address if it were only moved, and it would be more difficult to determine if a Vec had actually allocated memory.

  • It would penalize the general case, incurring an additional branch on every access.

Vec will never automatically shrink itself, even if completely empty. This ensures no unnecessary allocations or deallocations occur. Emptying a Vec and then filling it back up to the same len() should incur no calls to the allocator. If you wish to free up unused memory, use shrink_to_fit.

push and insert will never (re)allocate if the reported capacity is sufficient. push and insert will (re)allocate if len() == capacity(). That is, the reported capacity is completely accurate, and can be relied on. It can even be used to manually free the memory allocated by a Vec if desired. Bulk insertion methods may reallocate, even when not necessary.

Vec does not guarantee any particular growth strategy when reallocating when full, nor when reserve is called. The current strategy is basic and it may prove desirable to use a non-constant growth factor. Whatever strategy is used will of course guarantee O(1) amortized push.

vec![x; n], vec![a, b, c, d], and Vec::with_capacity(n), will all produce a Vec with exactly the requested capacity. If len() == capacity(), (as is the case for the vec! macro), then a Vec<T> can be converted to and from a Box<[T]> without reallocating or moving the elements.

Vec will not specifically overwrite any data that is removed from it, but also won't specifically preserve it. Its uninitialized memory is scratch space that it may use however it wants. It will generally just do whatever is most efficient or otherwise easy to implement. Do not rely on removed data to be erased for security purposes. Even if you drop a Vec, its buffer may simply be reused by another Vec. Even if you zero a Vec's memory first, that may not actually happen because the optimizer does not consider this a side-effect that must be preserved.

Vec does not currently guarantee the order in which elements are dropped (the order has changed in the past, and may change again).

fn new() -> Vec<T>

Constructs a new, empty Vec<T>.

The vector will not allocate until elements are pushed onto it.

Examples

fn main() { #![allow(unused_mut)] let mut vec: Vec<i32> = Vec::new(); }
let mut vec: Vec<i32> = Vec::new();

fn with_capacity(capacity: usize) -> Vec<T>

Constructs a new, empty Vec<T> with the specified capacity.

The vector will be able to hold exactly capacity elements without reallocating. If capacity is 0, the vector will not allocate.

It is important to note that this function does not specify the length of the returned vector, but only the capacity. (For an explanation of the difference between length and capacity, see the main Vec<T> docs above, 'Capacity and reallocation'.)

Examples

fn main() { let mut vec = Vec::with_capacity(10); // The vector contains no items, even though it has capacity for more assert_eq!(vec.len(), 0); // These are all done without reallocating... for i in 0..10 { vec.push(i); } // ...but this may make the vector reallocate vec.push(11); }
let mut vec = Vec::with_capacity(10);

// The vector contains no items, even though it has capacity for more
assert_eq!(vec.len(), 0);

// These are all done without reallocating...
for i in 0..10 {
    vec.push(i);
}

// ...but this may make the vector reallocate
vec.push(11);

fn into_vec(self: Box<[T]>) -> Vec<T>

Converts self into a vector without clones or allocation.

fn from(s: &'a [T]) -> Vec<T>

Performs the conversion.

fn from(s: &'a str) -> Vec<u8>

Performs the conversion.

fn from(other: VecDeque<T>) -> Vec<T>

Performs the conversion.

fn from(s: CString) -> Vec<u8>

Performs the conversion.

fn clone(&self) -> Vec<T>

Returns a copy of the value. Read more

Indexing

The Vec type allows to access values by index, because it implements the Index trait. An example will be more explicit:

fn main() { let v = vec!(0, 2, 4, 6); println!("{}", v[1]); // it will display '2' }
let v = vec!(0, 2, 4, 6);
println!("{}", v[1]); // it will display '2'

However be careful: if you try to access an index which isn't in the Vec, your software will panic! You cannot do this:

fn main() { let v = vec!(0, 2, 4, 6); println!("{}", v[6]); // it will panic! }
let v = vec!(0, 2, 4, 6);
println!("{}", v[6]); // it will panic!

In conclusion: always check if the index you want to get really exists before doing it.

fn len(&self) -> usize

Returns the number of elements in the vector.

Examples

fn main() { let a = vec![1, 2, 3]; assert_eq!(a.len(), 3); }
let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);

fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

Examples

fn main() { let mut v = Vec::new(); assert!(v.is_empty()); v.push(1); assert!(!v.is_empty()); }
let mut v = Vec::new();
assert!(v.is_empty());

v.push(1);
assert!(!v.is_empty());

fn first(&self) -> Option<&T>

Returns the first element of a slice, or None if it is empty.

Examples

fn main() { let v = [10, 40, 30]; assert_eq!(Some(&10), v.first()); let w: &[i32] = &[]; assert_eq!(None, w.first()); }
let v = [10, 40, 30];
assert_eq!(Some(&10), v.first());

let w: &[i32] = &[];
assert_eq!(None, w.first());

fn first_mut(&mut self) -> Option<&mut T>

Returns a mutable pointer to the first element of a slice, or None if it is empty

fn last(&self) -> Option<&T>

Returns the last element of a slice, or None if it is empty.

Examples

fn main() { let v = [10, 40, 30]; assert_eq!(Some(&30), v.last()); let w: &[i32] = &[]; assert_eq!(None, w.last()); }
let v = [10, 40, 30];
assert_eq!(Some(&30), v.last());

let w: &[i32] = &[];
assert_eq!(None, w.last());

fn last_mut(&mut self) -> Option<&mut T>

Returns a mutable pointer to the last item in the slice.

fn get(&self, index: usize) -> Option<&T>

Returns the element of a slice at the given index, or None if the index is out of bounds.

Examples

fn main() { let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(None, v.get(3)); }
let v = [10, 40, 30];
assert_eq!(Some(&40), v.get(1));
assert_eq!(None, v.get(3));

fn get_mut(&mut self, index: usize) -> Option<&mut T>

Returns a mutable reference to the element at the given index, or None if the index is out of bounds

fn contains(&self, x: &T) -> bool where T: PartialEq<T>

Returns true if the slice contains an element with the given value.

Examples

fn main() { let v = [10, 40, 30]; assert!(v.contains(&30)); assert!(!v.contains(&50)); }
let v = [10, 40, 30];
assert!(v.contains(&30));
assert!(!v.contains(&50));

fn binary_search_by<F>(&self, f: F) -> Result<usizeusize> where F: FnMut(&T) -> Ordering

Binary search a sorted slice with a comparator function.

The comparator function should implement an order consistent with the sort order of the underlying slice, returning an order code that indicates whether its argument is Less, Equal or Greater the desired target.

If a matching value is found then returns Ok, containing the index for the matched element; if no match is found then Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.

Example

Looks up a series of four elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in [1,4].

fn main() { let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; let seek = 13; assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Ok(9)); let seek = 4; assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Err(7)); let seek = 100; assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Err(13)); let seek = 1; let r = s.binary_search_by(|probe| probe.cmp(&seek)); assert!(match r { Ok(1...4) => true, _ => false, }); }
let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];

let seek = 13;
assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Ok(9));
let seek = 4;
assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Err(7));
let seek = 100;
assert_eq!(s.binary_search_by(|probe| probe.cmp(&seek)), Err(13));
let seek = 1;
let r = s.binary_search_by(|probe| probe.cmp(&seek));
assert!(match r { Ok(1...4) => true, _ => false, });

fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usizeusize> where B: Ord, F: FnMut(&T) -> B
1.10.0

Binary search a sorted slice with a key extraction function.

Assumes that the slice is sorted by the key, for instance with sort_by_key using the same key extraction function.

If a matching value is found then returns Ok, containing the index for the matched element; if no match is found then Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.

Examples

Looks up a series of four elements in a slice of pairs sorted by their second elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in [1,4].

fn main() { let s = [(0, 0), (2, 1), (4, 1), (5, 1), (3, 1), (1, 2), (2, 3), (4, 5), (5, 8), (3, 13), (1, 21), (2, 34), (4, 55)]; assert_eq!(s.binary_search_by_key(&13, |&(a,b)| b), Ok(9)); assert_eq!(s.binary_search_by_key(&4, |&(a,b)| b), Err(7)); assert_eq!(s.binary_search_by_key(&100, |&(a,b)| b), Err(13)); let r = s.binary_search_by_key(&1, |&(a,b)| b); assert!(match r { Ok(1...4) => true, _ => false, }); }
let s = [(0, 0), (2, 1), (4, 1), (5, 1), (3, 1),
         (1, 2), (2, 3), (4, 5), (5, 8), (3, 13),
         (1, 21), (2, 34), (4, 55)];

assert_eq!(s.binary_search_by_key(&13, |&(a,b)| b),  Ok(9));
assert_eq!(s.binary_search_by_key(&4, |&(a,b)| b),   Err(7));
assert_eq!(s.binary_search_by_key(&100, |&(a,b)| b), Err(13));
let r = s.binary_search_by_key(&1, |&(a,b)| b);
assert!(match r { Ok(1...4) => true, _ => false, });

fn ends_with(&self, needle: &[T]) -> bool where T: PartialEq<T>

Returns true if needle is a suffix of the slice.

Examples

fn main() { let v = [10, 40, 30]; assert!(v.ends_with(&[30])); assert!(v.ends_with(&[40, 30])); assert!(!v.ends_with(&[50])); assert!(!v.ends_with(&[50, 30])); }
let v = [10, 40, 30];
assert!(v.ends_with(&[30]));
assert!(v.ends_with(&[40, 30]));
assert!(!v.ends_with(&[50]));
assert!(!v.ends_with(&[50, 30]));

fn starts_with(&self, needle: &[T]) -> bool where T: PartialEq<T>

Returns true if needle is a prefix of the slice.

Examples

fn main() { let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); }
let v = [10, 40, 30];
assert!(v.starts_with(&[10]));
assert!(v.starts_with(&[10, 40]));
assert!(!v.starts_with(&[50]));
assert!(!v.starts_with(&[10, 50]));

fn push(&mut self, value: T)

Appends an element to the back of a collection.

Panics

Panics if the number of elements in the vector overflows a usize.

Examples

fn main() { let mut vec = vec![1, 2]; vec.push(3); assert_eq!(vec, [1, 2, 3]); }
let mut vec = vec![1, 2];
vec.push(3);
assert_eq!(vec, [1, 2, 3]);

fn insert(&mut self, index: usize, element: T)

Inserts an element at position index within the vector, shifting all elements after it to the right.

Panics

Panics if index is greater than the vector's length.

Examples

fn main() { let mut vec = vec![1, 2, 3]; vec.insert(1, 4); assert_eq!(vec, [1, 4, 2, 3]); vec.insert(4, 5); assert_eq!(vec, [1, 4, 2, 3, 5]); }
let mut vec = vec![1, 2, 3];
vec.insert(1, 4);
assert_eq!(vec, [1, 4, 2, 3]);
vec.insert(4, 5);
assert_eq!(vec, [1, 4, 2, 3, 5]);

fn extend<I>(&mut self, iter: I) where I: IntoIterator<Item=T>

Extends a collection with the contents of an iterator. Read more

fn extend_from_slice(&mut self, other: &[T])
1.6.0

Clones and appends all elements in a slice to the Vec.

Iterates over the slice other, clones each element, and then appends it to this Vec. The other vector is traversed in-order.

Note that this function is same as extend except that it is specialized to work with slices instead. If and when Rust gets specialization this function will likely be deprecated (but still available).

Examples

fn main() { let mut vec = vec![1]; vec.extend_from_slice(&[2, 3, 4]); assert_eq!(vec, [1, 2, 3, 4]); }
let mut vec = vec![1];
vec.extend_from_slice(&[2, 3, 4]);
assert_eq!(vec, [1, 2, 3, 4]);

fn append(&mut self, other: &mut Vec<T>)
1.4.0

Moves all the elements of other into Self, leaving other empty.

Panics

Panics if the number of elements in the vector overflows a usize.

Examples

fn main() { let mut vec = vec![1, 2, 3]; let mut vec2 = vec![4, 5, 6]; vec.append(&mut vec2); assert_eq!(vec, [1, 2, 3, 4, 5, 6]); assert_eq!(vec2, []); }
let mut vec = vec![1, 2, 3];
let mut vec2 = vec![4, 5, 6];
vec.append(&mut vec2);
assert_eq!(vec, [1, 2, 3, 4, 5, 6]);
assert_eq!(vec2, []);

fn clone_from(&mut self, other: &Vec<T>)

Performs copy-assignment from source. Read more

fn clone_from_slice(&mut self, src: &[T]) where T: Clone
1.7.0

Copies the elements from src into self.

The length of this slice must be the same as the slice passed in.

Panics

This function will panic if the two slices have different lengths.

Example

fn main() { let mut dst = [0, 0, 0]; let src = [1, 2, 3]; dst.clone_from_slice(&src); assert!(dst == [1, 2, 3]); }
let mut dst = [0, 0, 0];
let src = [1, 2, 3];

dst.clone_from_slice(&src);
assert!(dst == [1, 2, 3]);

fn copy_from_slice(&mut self, src: &[T]) where T: Copy
1.9.0

Copies all elements from src into self, using a memcpy.

The length of src must be the same as self.

Panics

This function will panic if the two slices have different lengths.

Example

fn main() { let mut dst = [0, 0, 0]; let src = [1, 2, 3]; dst.copy_from_slice(&src); assert_eq!(src, dst); }
let mut dst = [0, 0, 0];
let src = [1, 2, 3];

dst.copy_from_slice(&src);
assert_eq!(src, dst);

fn pop(&mut self) -> Option<T>

Removes the last element from a vector and returns it, or None if it is empty.

Examples

fn main() { let mut vec = vec![1, 2, 3]; assert_eq!(vec.pop(), Some(3)); assert_eq!(vec, [1, 2]); }
let mut vec = vec![1, 2, 3];
assert_eq!(vec.pop(), Some(3));
assert_eq!(vec, [1, 2]);

fn remove(&mut self, index: usize) -> T

Removes and returns the element at position index within the vector, shifting all elements after it to the left.

Panics

Panics if index is out of bounds.

Examples

fn main() { let mut v = vec![1, 2, 3]; assert_eq!(v.remove(1), 2); assert_eq!(v, [1, 3]); }
let mut v = vec![1, 2, 3];
assert_eq!(v.remove(1), 2);
assert_eq!(v, [1, 3]);

fn swap_remove(&mut self, index: usize) -> T

Removes an element from anywhere in the vector and return it, replacing it with the last element.

This does not preserve ordering, but is O(1).

Panics

Panics if index is out of bounds.

Examples

fn main() { let mut v = vec!["foo", "bar", "baz", "qux"]; assert_eq!(v.swap_remove(1), "bar"); assert_eq!(v, ["foo", "qux", "baz"]); assert_eq!(v.swap_remove(0), "foo"); assert_eq!(v, ["baz", "qux"]); }
let mut v = vec!["foo", "bar", "baz", "qux"];

assert_eq!(v.swap_remove(1), "bar");
assert_eq!(v, ["foo", "qux", "baz"]);

assert_eq!(v.swap_remove(0), "foo");
assert_eq!(v, ["baz", "qux"]);

fn truncate(&mut self, len: usize)

Shorten a vector to be len elements long, dropping excess elements.

If len is greater than the vector's current length, this has no effect.

Examples

fn main() { let mut vec = vec![1, 2, 3, 4, 5]; vec.truncate(2); assert_eq!(vec, [1, 2]); }
let mut vec = vec![1, 2, 3, 4, 5];
vec.truncate(2);
assert_eq!(vec, [1, 2]);

fn drain<R>(&mut self, range: R) -> Drain<T> where R: RangeArgument<usize>
1.6.0

Create a draining iterator that removes the specified range in the vector and yields the removed items.

Note 1: The element range is removed even if the iterator is not consumed until the end.

Note 2: It is unspecified how many elements are removed from the vector, if the Drain value is leaked.

Panics

Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.

Examples

fn main() { let mut v = vec![1, 2, 3]; let u: Vec<_> = v.drain(1..).collect(); assert_eq!(v, &[1]); assert_eq!(u, &[2, 3]); // A full range clears the vector v.drain(..); assert_eq!(v, &[]); }
let mut v = vec![1, 2, 3];
let u: Vec<_> = v.drain(1..).collect();
assert_eq!(v, &[1]);
assert_eq!(u, &[2, 3]);

// A full range clears the vector
v.drain(..);
assert_eq!(v, &[]);

fn clear(&mut self)

Clears the vector, removing all values.

Examples

fn main() { let mut v = vec![1, 2, 3]; v.clear(); assert!(v.is_empty()); }
let mut v = vec![1, 2, 3];

v.clear();

assert!(v.is_empty());

fn retain<F>(&mut self, f: F) where F: FnMut(&T) -> bool

Retains only the elements specified by the predicate.

In other words, remove all elements e such that f(&e) returns false. This method operates in place and preserves the order of the retained elements.

Examples

fn main() { let mut vec = vec![1, 2, 3, 4]; vec.retain(|&x| x%2 == 0); assert_eq!(vec, [2, 4]); }
let mut vec = vec![1, 2, 3, 4];
vec.retain(|&x| x%2 == 0);
assert_eq!(vec, [2, 4]);

fn dedup(&mut self)

Removes consecutive repeated elements in the vector.

If the vector is sorted, this removes all duplicates.

Examples

fn main() { let mut vec = vec![1, 2, 2, 3, 2]; vec.dedup(); assert_eq!(vec, [1, 2, 3, 2]); }
let mut vec = vec![1, 2, 2, 3, 2];

vec.dedup();

assert_eq!(vec, [1, 2, 3, 2]);

fn sort(&mut self) where T: Ord

This is equivalent to self.sort_by(|a, b| a.cmp(b)).

This sort is stable and O(n log n) worst-case but allocates approximately 2 * n where n is the length of self.

Examples

fn main() { let mut v = [-5, 4, 1, -3, 2]; v.sort(); assert!(v == [-5, -3, 1, 2, 4]); }
let mut v = [-5, 4, 1, -3, 2];

v.sort();
assert!(v == [-5, -3, 1, 2, 4]);

fn sort_by<F>(&mut self, compare: F) where F: FnMut(&T, &T) -> Ordering

Sorts the slice, in place, using compare to compare elements.

This sort is stable and O(n log n) worst-case but allocates approximately 2 * n, where n is the length of self.

Examples

fn main() { let mut v = [5, 4, 1, 3, 2]; v.sort_by(|a, b| a.cmp(b)); assert!(v == [1, 2, 3, 4, 5]); // reverse sorting v.sort_by(|a, b| b.cmp(a)); assert!(v == [5, 4, 3, 2, 1]); }
let mut v = [5, 4, 1, 3, 2];
v.sort_by(|a, b| a.cmp(b));
assert!(v == [1, 2, 3, 4, 5]);

// reverse sorting
v.sort_by(|a, b| b.cmp(a));
assert!(v == [5, 4, 3, 2, 1]);

fn sort_by_key<B, F>(&mut self, f: F) where B: Ord, F: FnMut(&T) -> B
1.7.0

Sorts the slice, in place, using key to extract a key by which to order the sort by.

This sort is stable and O(n log n) worst-case but allocates approximately 2 * n, where n is the length of self.

Examples

fn main() { let mut v = [-5i32, 4, 1, -3, 2]; v.sort_by_key(|k| k.abs()); assert!(v == [1, 2, -3, 4, -5]); }
let mut v = [-5i32, 4, 1, -3, 2];

v.sort_by_key(|k| k.abs());
assert!(v == [1, 2, -3, 4, -5]);

fn reverse(&mut self)

Reverse the order of elements in a slice, in place.

Example

fn main() { let mut v = [1, 2, 3]; v.reverse(); assert!(v == [3, 2, 1]); }
let mut v = [1, 2, 3];
v.reverse();
assert!(v == [3, 2, 1]);

fn swap(&mut self, a: usize, b: usize)

Swaps two elements in a slice.

Arguments

  • a - The index of the first element
  • b - The index of the second element

Panics

Panics if a or b are out of bounds.

Example

fn main() { let mut v = ["a", "b", "c", "d"]; v.swap(1, 3); assert!(v == ["a", "d", "c", "b"]); }
let mut v = ["a", "b", "c", "d"];
v.swap(1, 3);
assert!(v == ["a", "d", "c", "b"]);

fn iter(&self) -> Iter<T>

Returns an iterator over the slice.

fn iter_mut(&mut self) -> IterMut<T>

Returns an iterator that allows modifying each value

fn into_iter(self) -> IntoIter<T>

Creates a consuming iterator, that is, one that moves each value out of the vector (from start to end). The vector cannot be used after calling this.

Examples

fn main() { let v = vec!["a".to_string(), "b".to_string()]; for s in v.into_iter() { // s has type String, not &String println!("{}", s); } }
let v = vec!["a".to_string(), "b".to_string()];
for s in v.into_iter() {
    // s has type String, not &String
    println!("{}", s);
}

fn chunks(&self, size: usize) -> Chunks<T>

Returns an iterator over size elements of the slice at a time. The chunks are slices and do not overlap. If size does not divide the length of the slice, then the last chunk will not have length size.

Panics

Panics if size is 0.

Example

Print the slice two elements at a time (i.e. [1,2], [3,4], [5]):

fn main() { let v = &[1, 2, 3, 4, 5]; for chunk in v.chunks(2) { println!("{:?}", chunk); } }
let v = &[1, 2, 3, 4, 5];
for chunk in v.chunks(2) {
    println!("{:?}", chunk);
}

fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<T>

Returns an iterator over chunk_size elements of the slice at a time. The chunks are mutable slices, and do not overlap. If chunk_size does not divide the length of the slice, then the last chunk will not have length chunk_size.

Panics

Panics if chunk_size is 0.

fn windows(&self, size: usize) -> Windows<T>

Returns an iterator over all contiguous windows of length size. The windows overlap. If the slice is shorter than size, the iterator returns no values.

Panics

Panics if size is 0.

Example

Print the adjacent pairs of a slice (i.e. [1,2], [2,3], [3,4]):

fn main() { let v = &[1, 2, 3, 4]; for win in v.windows(2) { println!("{:?}", win); } }
let v = &[1, 2, 3, 4];
for win in v.windows(2) {
    println!("{:?}", win);
}

fn into_boxed_slice(self) -> Box<[T]>

Converts the vector into Box<[T]>.

Note that this will drop any excess capacity. Calling this and converting back to a vector with into_vec() is equivalent to calling shrink_to_fit().

fn as_ref(&self) -> &Vec<T>

Performs the conversion.

fn to_vec(&self) -> Vec<T> where T: Clone

Copies self into a new Vec.

fn as_slice(&self) -> &[T]
1.7.0

Extracts a slice containing the entire vector.

Equivalent to &s[..].

fn as_mut_slice(&mut self) -> &mut [T]
1.7.0

Extracts a mutable slice of the entire vector.

Equivalent to &mut s[..].

fn capacity(&self) -> usize

Returns the number of elements the vector can hold without reallocating.

Examples

fn main() { let vec: Vec<i32> = Vec::with_capacity(10); assert_eq!(vec.capacity(), 10); }
let vec: Vec<i32> = Vec::with_capacity(10);
assert_eq!(vec.capacity(), 10);

fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the given Vec<T>. The collection may reserve more space to avoid frequent reallocations.

Panics

Panics if the new capacity overflows usize.

Examples

fn main() { let mut vec = vec![1]; vec.reserve(10); assert!(vec.capacity() >= 11); }
let mut vec = vec![1];
vec.reserve(10);
assert!(vec.capacity() >= 11);

fn reserve_exact(&mut self, additional: usize)

Reserves the minimum capacity for exactly additional more elements to be inserted in the given Vec<T>. Does nothing if the capacity is already sufficient.

Note that the allocator may give the collection more space than it requests. Therefore capacity can not be relied upon to be precisely minimal. Prefer reserve if future insertions are expected.

Panics

Panics if the new capacity overflows usize.

Examples

fn main() { let mut vec = vec![1]; vec.reserve_exact(10); assert!(vec.capacity() >= 11); }
let mut vec = vec![1];
vec.reserve_exact(10);
assert!(vec.capacity() >= 11);

fn shrink_to_fit(&mut self)

Shrinks the capacity of the vector as much as possible.

It will drop down as close as possible to the length but the allocator may still inform the vector that there is space for a few more elements.

Examples

fn main() { let mut vec = Vec::with_capacity(10); vec.extend([1, 2, 3].iter().cloned()); assert_eq!(vec.capacity(), 10); vec.shrink_to_fit(); assert!(vec.capacity() >= 3); }
let mut vec = Vec::with_capacity(10);
vec.extend([1, 2, 3].iter().cloned());
assert_eq!(vec.capacity(), 10);
vec.shrink_to_fit();
assert!(vec.capacity() >= 3);

fn split_at(&self, mid: usize) -> (&[T], &[T])

Divides one slice into two at an index.

The first will contain all indices from [0, mid) (excluding the index mid itself) and the second will contain all indices from [mid, len) (excluding the index len itself).

Panics

Panics if mid > len.

Examples

fn main() { let v = [10, 40, 30, 20, 50]; let (v1, v2) = v.split_at(2); assert_eq!([10, 40], v1); assert_eq!([30, 20, 50], v2); }
let v = [10, 40, 30, 20, 50];
let (v1, v2) = v.split_at(2);
assert_eq!([10, 40], v1);
assert_eq!([30, 20, 50], v2);

fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T])

Divides one &mut into two at an index.

The first will contain all indices from [0, mid) (excluding the index mid itself) and the second will contain all indices from [mid, len) (excluding the index len itself).

Panics

Panics if mid > len.

Example

fn main() { let mut v = [1, 2, 3, 4, 5, 6]; // scoped to restrict the lifetime of the borrows { let (left, right) = v.split_at_mut(0); assert!(left == []); assert!(right == [1, 2, 3, 4, 5, 6]); } { let (left, right) = v.split_at_mut(2); assert!(left == [1, 2]); assert!(right == [3, 4, 5, 6]); } { let (left, right) = v.split_at_mut(6); assert!(left == [1, 2, 3, 4, 5, 6]); assert!(right == []); } }
let mut v = [1, 2, 3, 4, 5, 6];

// scoped to restrict the lifetime of the borrows
{
   let (left, right) = v.split_at_mut(0);
   assert!(left == []);
   assert!(right == [1, 2, 3, 4, 5, 6]);
}

{
    let (left, right) = v.split_at_mut(2);
    assert!(left == [1, 2]);
    assert!(right == [3, 4, 5, 6]);
}

{
    let (left, right) = v.split_at_mut(6);
    assert!(left == [1, 2, 3, 4, 5, 6]);
    assert!(right == []);
}

fn split<F>(&self, pred: F) -> Split<T, F> where F: FnMut(&T) -> bool

Returns an iterator over subslices separated by elements that match pred. The matched element is not contained in the subslices.

Examples

Print the slice split by numbers divisible by 3 (i.e. [10, 40], [20], [50]):

fn main() { let v = [10, 40, 30, 20, 60, 50]; for group in v.split(|num| *num % 3 == 0) { println!("{:?}", group); } }
let v = [10, 40, 30, 20, 60, 50];
for group in v.split(|num| *num % 3 == 0) {
    println!("{:?}", group);
}

fn split_mut<F>(&mut self, pred: F) -> SplitMut<T, F> where F: FnMut(&T) -> bool

Returns an iterator over mutable subslices separated by elements that match pred. The matched element is not contained in the subslices.

fn splitn<F>(&self, n: usize, pred: F) -> SplitN<T, F> where F: FnMut(&T) -> bool

Returns an iterator over subslices separated by elements that match pred, limited to returning at most n items. The matched element is not contained in the subslices.

The last element returned, if any, will contain the remainder of the slice.

Examples

Print the slice split once by numbers divisible by 3 (i.e. [10, 40], [20, 60, 50]):

fn main() { let v = [10, 40, 30, 20, 60, 50]; for group in v.splitn(2, |num| *num % 3 == 0) { println!("{:?}", group); } }
let v = [10, 40, 30, 20, 60, 50];
for group in v.splitn(2, |num| *num % 3 == 0) {
    println!("{:?}", group);
}

fn splitn_mut<F>(&mut self, n: usize, pred: F) -> SplitNMut<T, F> where F: FnMut(&T) -> bool

Returns an iterator over subslices separated by elements that match pred, limited to returning at most n items. The matched element is not contained in the subslices.

The last element returned, if any, will contain the remainder of the slice.

fn rsplitn<F>(&self, n: usize, pred: F) -> RSplitN<T, F> where F: FnMut(&T) -> bool

Returns an iterator over subslices separated by elements that match pred limited to returning at most n items. This starts at the end of the slice and works backwards. The matched element is not contained in the subslices.

The last element returned, if any, will contain the remainder of the slice.

Examples

Print the slice split once, starting from the end, by numbers divisible by 3 (i.e. [50], [10, 40, 30, 20]):

fn main() { let v = [10, 40, 30, 20, 60, 50]; for group in v.rsplitn(2, |num| *num % 3 == 0) { println!("{:?}", group); } }
let v = [10, 40, 30, 20, 60, 50];
for group in v.rsplitn(2, |num| *num % 3 == 0) {
    println!("{:?}", group);
}

fn rsplitn_mut<F>(&mut self, n: usize, pred: F) -> RSplitNMut<T, F> where F: FnMut(&T) -> bool

Returns an iterator over subslices separated by elements that match pred limited to returning at most n items. This starts at the end of the slice and works backwards. The matched element is not contained in the subslices.

The last element returned, if any, will contain the remainder of the slice.

fn split_off(&mut self, at: usize) -> Vec<T>
1.4.0

Splits the collection into two at the given index.

Returns a newly allocated Self. self contains elements [0, at), and the returned Self contains elements [at, len).

Note that the capacity of self does not change.

Panics

Panics if at > len.

Examples

fn main() { let mut vec = vec![1,2,3]; let vec2 = vec.split_off(1); assert_eq!(vec, [1]); assert_eq!(vec2, [2, 3]); }
let mut vec = vec![1,2,3];
let vec2 = vec.split_off(1);
assert_eq!(vec, [1]);
assert_eq!(vec2, [2, 3]);

fn cmp(&self, other: &Vec<T>) -> Ordering

This method returns an Ordering between self and other. Read more

fn eq(&self, other: &Vec<B>) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Vec<B>) -> bool

This method tests for !=.

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

fn hash<H>(&self, state: &mut H) where H: Hasher

Feeds this value into the state given, updating the hasher as necessary.

impl<T> From<BinaryHeap<T>> for Vec<T>

fn from(heap: BinaryHeap<T>) -> Vec<T>

Performs the conversion.

impl<T> Borrow<[T]> for Vec<T>

fn borrow(&self) -> &[T]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<[T]> for Vec<T>

fn borrow_mut(&mut self) -> &mut [T]

Mutably borrows from an owned value. Read more

impl<T> Clone for Vec<T> where T: Clone

fn clone(&self) -> Vec<T>

Returns a copy of the value. Read more

fn clone_from(&mut self, other: &Vec<T>)

Performs copy-assignment from source. Read more

impl<T> Hash for Vec<T> where T: Hash

fn hash<H>(&self, state: &mut H) where H: Hasher

Feeds this value into the state given, updating the hasher as necessary.

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0

Feeds a slice of this type into the state provided.

impl<T> Index<usize> for Vec<T>

type Output = T

The returned type after indexing

fn index(&self, index: usize) -> &T

The method for the indexing (Foo[Bar]) operation

impl<T> IndexMut<usize> for Vec<T>

fn index_mut(&mut self, index: usize) -> &mut T

The method for the indexing (Foo[Bar]) operation

impl<T> Index<Range<usize>> for Vec<T>

type Output = [T]

The returned type after indexing

fn index(&self, index: Range<usize>) -> &[T]

The method for the indexing (Foo[Bar]) operation

impl<T> Index<RangeTo<usize>> for Vec<T>

type Output = [T]

The returned type after indexing

fn index(&self, index: RangeTo<usize>) -> &[T]

The method for the indexing (Foo[Bar]) operation

impl<T> Index<RangeFrom<usize>> for Vec<T>

type Output = [T]

The returned type after indexing

fn index(&self, index: RangeFrom<usize>) -> &[T]

The method for the indexing (Foo[Bar]) operation

impl<T> Index<RangeFull> for Vec<T>

type Output = [T]

The returned type after indexing

fn index(&self, _index: RangeFull) -> &[T]

The method for the indexing (Foo[Bar]) operation

impl<T> Index<RangeInclusive<usize>> for Vec<T>

type Output = [T]

The returned type after indexing

fn index(&self, index: RangeInclusive<usize>) -> &[T]

The method for the indexing (Foo[Bar]) operation

impl<T> Index<RangeToInclusive<usize>> for Vec<T>

type Output = [T]

The returned type after indexing

fn index(&self, index: RangeToInclusive<usize>) -> &[T]

The method for the indexing (Foo[Bar]) operation

impl<T> IndexMut<Range<usize>> for Vec<T>

fn index_mut(&mut self, index: Range<usize>) -> &mut [T]

The method for the indexing (Foo[Bar]) operation

impl<T> IndexMut<RangeTo<usize>> for Vec<T>

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut [T]

The method for the indexing (Foo[Bar]) operation

impl<T> IndexMut<RangeFrom<usize>> for Vec<T>

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut [T]

The method for the indexing (Foo[Bar]) operation

impl<T> IndexMut<RangeFull> for Vec<T>

fn index_mut(&mut self, _index: RangeFull) -> &mut [T]

The method for the indexing (Foo[Bar]) operation

impl<T> IndexMut<RangeInclusive<usize>> for Vec<T>

fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut [T]

The method for the indexing (Foo[Bar]) operation

impl<T> IndexMut<RangeToInclusive<usize>> for Vec<T>

fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut [T]

The method for the indexing (Foo[Bar]) operation

impl<T> Deref for Vec<T>

type Target = [T]

The resulting type after dereferencing

fn deref(&self) -> &[T]

The method called to dereference a value

impl<T> DerefMut for Vec<T>

fn deref_mut(&mut self) -> &mut [T]

The method called to mutably dereference a value

impl<T> FromIterator<T> for Vec<T>

fn from_iter<I>(iter: I) -> Vec<T> where I: IntoIterator<Item=T>

Creates a value from an iterator. Read more

impl<T> IntoIterator for Vec<T>

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> IntoIter<T>

Creates a consuming iterator, that is, one that moves each value out of the vector (from start to end). The vector cannot be used after calling this.

Examples

fn main() { let v = vec!["a".to_string(), "b".to_string()]; for s in v.into_iter() { // s has type String, not &String println!("{}", s); } }
let v = vec!["a".to_string(), "b".to_string()];
for s in v.into_iter() {
    // s has type String, not &String
    println!("{}", s);
}

impl<'a, T> IntoIterator for &'a Vec<T>

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more

impl<'a, T> IntoIterator for &'a mut Vec<T>

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> IterMut<'a, T>

Creates an iterator from a value. Read more

impl<T> Extend<T> for Vec<T>

fn extend<I>(&mut self, iter: I) where I: IntoIterator<Item=T>

Extends a collection with the contents of an iterator. Read more

impl<'a, T> Extend<&'a T> for Vec<T> where T: Copy + 'a
1.2.0

fn extend<I>(&mut self, iter: I) where I: IntoIterator<Item=&'a T>

Extends a collection with the contents of an iterator. Read more

impl<'a, 'b, A, B> PartialEq<Vec<B>> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &Vec<B>) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Vec<B>) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b mut [B]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b mut [B]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b mut [B]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 0]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 0]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 0]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 0]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 0]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 0]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 1]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 1]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 1]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 1]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 1]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 1]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 2]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 2]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 2]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 2]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 2]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 2]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 3]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 3]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 3]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 3]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 3]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 3]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 4]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 4]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 4]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 4]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 4]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 4]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 5]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 5]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 5]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 5]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 5]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 5]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 6]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 6]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 6]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 6]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 6]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 6]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 7]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 7]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 7]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 7]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 7]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 7]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 8]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 8]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 8]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 8]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 8]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 8]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 9]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 9]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 9]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 9]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 9]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 9]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 10]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 10]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 10]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 10]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 10]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 10]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 11]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 11]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 11]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 11]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 11]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 11]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 12]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 12]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 12]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 12]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 12]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 12]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 13]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 13]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 13]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 13]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 13]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 13]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 14]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 14]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 14]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 14]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 14]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 14]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 15]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 15]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 15]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 15]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 15]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 15]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 16]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 16]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 16]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 16]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 16]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 16]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 17]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 17]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 17]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 17]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 17]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 17]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 18]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 18]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 18]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 18]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 18]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 18]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 19]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 19]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 19]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 19]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 19]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 19]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 20]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 20]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 20]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 20]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 20]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 20]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 21]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 21]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 21]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 21]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 21]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 21]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 22]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 22]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 22]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 22]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 22]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 22]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 23]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 23]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 23]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 23]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 23]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 23]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 24]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 24]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 24]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 24]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 24]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 24]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 25]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 25]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 25]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 25]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 25]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 25]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 26]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 26]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 26]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 26]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 26]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 26]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 27]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 27]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 27]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 27]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 27]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 27]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 28]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 28]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 28]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 28]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 28]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 28]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 29]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 29]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 29]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 29]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 29]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 29]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 30]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 30]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 30]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 30]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 30]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 30]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 31]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 31]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 31]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 31]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 31]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 31]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<[B; 32]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &[B; 32]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &[B; 32]) -> bool

This method tests for !=.

impl<'a, 'b, A, B> PartialEq<&'b [B; 32]> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &&'b [B; 32]) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &&'b [B; 32]) -> bool

This method tests for !=.

impl<T> PartialOrd<Vec<T>> for Vec<T> where T: PartialOrd<T>

fn partial_cmp(&self, other: &Vec<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T> Eq for Vec<T> where T: Eq

impl<T> Ord for Vec<T> where T: Ord

fn cmp(&self, other: &Vec<T>) -> Ordering

This method returns an Ordering between self and other. Read more

impl<T> Drop for Vec<T>

fn drop(&mut self)

A method called when the value goes out of scope. Read more

impl<T> Default for Vec<T>

fn default() -> Vec<T>

Returns the "default value" for a type. Read more

impl<T> Debug for Vec<T> where T: Debug

fn fmt(&self, f: &mut Formatter) -> Result<()Error>

Formats the value using the given formatter.

impl<T> AsRef<Vec<T>> for Vec<T>

fn as_ref(&self) -> &Vec<T>

Performs the conversion.

impl<T> AsMut<Vec<T>> for Vec<T>
1.5.0

fn as_mut(&mut self) -> &mut Vec<T>

Performs the conversion.

impl<T> AsRef<[T]> for Vec<T>

fn as_ref(&self) -> &[T]

Performs the conversion.

impl<T> AsMut<[T]> for Vec<T>
1.5.0

fn as_mut(&mut self) -> &mut [T]

Performs the conversion.

impl<'a, T> From<&'a [T]> for Vec<T> where T: Clone

fn from(s: &'a [T]) -> Vec<T>

Performs the conversion.

impl<'a> From<&'a str> for Vec<u8>

fn from(s: &'a str) -> Vec<u8>

Performs the conversion.

impl<T> From<VecDeque<T>> for Vec<T>
1.10.0

fn from(other: VecDeque<T>) -> Vec<T>

Performs the conversion.

impl From<CString> for Vec<u8>
1.7.0
[src]

fn from(s: CString) -> Vec<u8>

Performs the conversion.

impl Write for Vec<u8>
[src]

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this object, returning how many bytes were written. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<()>

Attempts to write an entire buffer into this write. Read more

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<()>

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self where Self: Sized

Creates a "by reference" adaptor for this instance of Write. Read more

impl<'a, 'b, A, B> PartialEq<Vec<B>> for Vec<A> where A: PartialEq<B>

fn eq(&self, other: &Vec<B>) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Vec<B>) -> bool

This method tests for !=.

impl<T> PartialOrd<Vec<T>> for Vec<T> where T: PartialOrd<T>

fn partial_cmp(&self, other: &Vec<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T> Ord for Vec<T> where T: Ord

fn cmp(&self, other: &Vec<T>) -> Ordering

This method returns an Ordering between self and other. Read more

impl<T> Drop for Vec<T>

fn drop(&mut self)

A method called when the value goes out of scope. Read more

impl<T> Default for Vec<T>

fn default() -> Vec<T>

Returns the "default value" for a type. Read more

impl<T> Debug for Vec<T> where T: Debug

fn fmt(&self, f: &mut Formatter) -> Result<()Error>

Formats the value using the given formatter.

impl<T> AsRef<Vec<T>> for Vec<T>

fn as_ref(&self) -> &Vec<T>

Performs the conversion.

impl<T> AsMut<Vec<T>> for Vec<T>
1.5.0

fn as_mut(&mut self) -> &mut Vec<T>

Performs the conversion.

impl<T> AsRef<[T]> for Vec<T>

fn as_ref(&self) -> &[T]

Performs the conversion.

impl<T> AsMut<[T]> for Vec<T>
1.5.0

fn as_mut(&mut self) -> &mut [T]

Performs the conversion.

impl<'a, T> From<&'a [T]> for Vec<T> where T: Clone

fn from(s: &'a [T]) -> Vec<T>

Performs the conversion.

impl<'a> From<&'a str> for Vec<u8>

fn from(s: &'a str) -> Vec<u8>

Performs the conversion.

impl<T> From<VecDeque<T>> for Vec<T>
1.10.0

fn from(other: VecDeque<T>) -> Vec<T>

Performs the conversion.

impl From<CString> for Vec<u8>
1.7.0
[src]

fn from(s: CString) -> Vec<u8>

Performs the conversion.

impl Write for Vec<u8>
[src]

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this object, returning how many bytes were written. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<()>

Attempts to write an entire buffer into this write. Read more

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<()>

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self where Self: Sized

Creates a "by reference" adaptor for this instance of Write. Read more

std::vec! []

macro_rules! vec {
    ( $ elem : expr ; $ n : expr ) => { ... };
    ( $ ( $ x : expr ) , * ) => { ... };
    ( $ ( $ x : expr , ) * ) => { ... };
}

Creates a Vec containing the arguments.

vec! allows Vecs to be defined with the same syntax as array expressions. There are two forms of this macro:

  • Create a Vec containing a given list of elements:
fn main() { let v = vec![1, 2, 3]; assert_eq!(v[0], 1); assert_eq!(v[1], 2); assert_eq!(v[2], 3); }
let v = vec![1, 2, 3];
assert_eq!(v[0], 1);
assert_eq!(v[1], 2);
assert_eq!(v[2], 3);
  • Create a Vec from a given element and size:
fn main() { let v = vec![1; 3]; assert_eq!(v, [1, 1, 1]); }
let v = vec![1; 3];
assert_eq!(v, [1, 1, 1]);

Note that unlike array expressions this syntax supports all elements which implement Clone and the number of elements doesn't have to be a constant.

This will use clone() to duplicate an expression, so one should be careful using this with types having a nonstandard Clone implementation. For example, vec![Rc::new(1); 5] will create a vector of five references to the same boxed integer value, not five references pointing to independently boxed integers.

Trait std::iter::IntoIterator1.0.0 [] [src]

pub trait IntoIterator where Self::IntoIter::Item == Self::Item {
    type Item;
    type IntoIter: Iterator;
    fn into_iter(self) -> Self::IntoIter;
}

Conversion into an Iterator.

By implementing IntoIterator for a type, you define how it will be converted to an iterator. This is common for types which describe a collection of some kind.

One benefit of implementing IntoIterator is that your type will work with Rust's for loop syntax.

See also: FromIterator.

Examples

Basic usage:

fn main() { let v = vec![1, 2, 3]; let mut iter = v.into_iter(); let n = iter.next(); assert_eq!(Some(1), n); let n = iter.next(); assert_eq!(Some(2), n); let n = iter.next(); assert_eq!(Some(3), n); let n = iter.next(); assert_eq!(None, n); }
let v = vec![1, 2, 3];

let mut iter = v.into_iter();

let n = iter.next();
assert_eq!(Some(1), n);

let n = iter.next();
assert_eq!(Some(2), n);

let n = iter.next();
assert_eq!(Some(3), n);

let n = iter.next();
assert_eq!(None, n);

Implementing IntoIterator for your type:

fn main() { // A sample collection, that's just a wrapper over Vec<T> #[derive(Debug)] struct MyCollection(Vec<i32>); // Let's give it some methods so we can create one and add things // to it. impl MyCollection { fn new() -> MyCollection { MyCollection(Vec::new()) } fn add(&mut self, elem: i32) { self.0.push(elem); } } // and we'll implement IntoIterator impl IntoIterator for MyCollection { type Item = i32; type IntoIter = ::std::vec::IntoIter<i32>; fn into_iter(self) -> Self::IntoIter { self.0.into_iter() } } // Now we can make a new collection... let mut c = MyCollection::new(); // ... add some stuff to it ... c.add(0); c.add(1); c.add(2); // ... and then turn it into an Iterator: for (i, n) in c.into_iter().enumerate() { assert_eq!(i as i32, n); } }
// A sample collection, that's just a wrapper over Vec<T>
#[derive(Debug)]
struct MyCollection(Vec<i32>);

// Let's give it some methods so we can create one and add things
// to it.
impl MyCollection {
    fn new() -> MyCollection {
        MyCollection(Vec::new())
    }

    fn add(&mut self, elem: i32) {
        self.0.push(elem);
    }
}

// and we'll implement IntoIterator
impl IntoIterator for MyCollection {
    type Item = i32;
    type IntoIter = ::std::vec::IntoIter<i32>;

    fn into_iter(self) -> Self::IntoIter {
        self.0.into_iter()
    }
}

// Now we can make a new collection...
let mut c = MyCollection::new();

// ... add some stuff to it ...
c.add(0);
c.add(1);
c.add(2);

// ... and then turn it into an Iterator:
for (i, n) in c.into_iter().enumerate() {
    assert_eq!(i as i32, n);
}

Associated Types

type Item

The type of the elements being iterated over.

type IntoIter: Iterator

Which kind of iterator are we turning this into?

Required Methods

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value.

See the module-level documentation for more.

Examples

Basic usage:

fn main() { let v = vec![1, 2, 3]; let mut iter = v.into_iter(); let n = iter.next(); assert_eq!(Some(1), n); let n = iter.next(); assert_eq!(Some(2), n); let n = iter.next(); assert_eq!(Some(3), n); let n = iter.next(); assert_eq!(None, n); }
let v = vec![1, 2, 3];

let mut iter = v.into_iter();

let n = iter.next();
assert_eq!(Some(1), n);

let n = iter.next();
assert_eq!(Some(2), n);

let n = iter.next();
assert_eq!(Some(3), n);

let n = iter.next();
assert_eq!(None, n);

Implementors

  • impl<'a, T> IntoIterator for &'a [T; 0]
  • impl<'a, T> IntoIterator for &'a mut [T; 0]
  • impl<'a, T> IntoIterator for &'a [T; 1]
  • impl<'a, T> IntoIterator for &'a mut [T; 1]
  • impl<'a, T> IntoIterator for &'a [T; 2]
  • impl<'a, T> IntoIterator for &'a mut [T; 2]
  • impl<'a, T> IntoIterator for &'a [T; 3]
  • impl<'a, T> IntoIterator for &'a mut [T; 3]
  • impl<'a, T> IntoIterator for &'a [T; 4]
  • impl<'a, T> IntoIterator for &'a mut [T; 4]
  • impl<'a, T> IntoIterator for &'a [T; 5]
  • impl<'a, T> IntoIterator for &'a mut [T; 5]
  • impl<'a, T> IntoIterator for &'a [T; 6]
  • impl<'a, T> IntoIterator for &'a mut [T; 6]
  • impl<'a, T> IntoIterator for &'a [T; 7]
  • impl<'a, T> IntoIterator for &'a mut [T; 7]
  • impl<'a, T> IntoIterator for &'a [T; 8]
  • impl<'a, T> IntoIterator for &'a mut [T; 8]
  • impl<'a, T> IntoIterator for &'a [T; 9]
  • impl<'a, T> IntoIterator for &'a mut [T; 9]
  • impl<'a, T> IntoIterator for &'a [T; 10]
  • impl<'a, T> IntoIterator for &'a mut [T; 10]
  • impl<'a, T> IntoIterator for &'a [T; 11]
  • impl<'a, T> IntoIterator for &'a mut [T; 11]
  • impl<'a, T> IntoIterator for &'a [T; 12]
  • impl<'a, T> IntoIterator for &'a mut [T; 12]
  • impl<'a, T> IntoIterator for &'a [T; 13]
  • impl<'a, T> IntoIterator for &'a mut [T; 13]
  • impl<'a, T> IntoIterator for &'a [T; 14]
  • impl<'a, T> IntoIterator for &'a mut [T; 14]
  • impl<'a, T> IntoIterator for &'a [T; 15]
  • impl<'a, T> IntoIterator for &'a mut [T; 15]
  • impl<'a, T> IntoIterator for &'a [T; 16]
  • impl<'a, T> IntoIterator for &'a mut [T; 16]
  • impl<'a, T> IntoIterator for &'a [T; 17]
  • impl<'a, T> IntoIterator for &'a mut [T; 17]
  • impl<'a, T> IntoIterator for &'a [T; 18]
  • impl<'a, T> IntoIterator for &'a mut [T; 18]
  • impl<'a, T> IntoIterator for &'a [T; 19]
  • impl<'a, T> IntoIterator for &'a mut [T; 19]
  • impl<'a, T> IntoIterator for &'a [T; 20]
  • impl<'a, T> IntoIterator for &'a mut [T; 20]
  • impl<'a, T> IntoIterator for &'a [T; 21]
  • impl<'a, T> IntoIterator for &'a mut [T; 21]
  • impl<'a, T> IntoIterator for &'a [T; 22]
  • impl<'a, T> IntoIterator for &'a mut [T; 22]
  • impl<'a, T> IntoIterator for &'a [T; 23]
  • impl<'a, T> IntoIterator for &'a mut [T; 23]
  • impl<'a, T> IntoIterator for &'a [T; 24]
  • impl<'a, T> IntoIterator for &'a mut [T; 24]
  • impl<'a, T> IntoIterator for &'a [T; 25]
  • impl<'a, T> IntoIterator for &'a mut [T; 25]
  • impl<'a, T> IntoIterator for &'a [T; 26]
  • impl<'a, T> IntoIterator for &'a mut [T; 26]
  • impl<'a, T> IntoIterator for &'a [T; 27]
  • impl<'a, T> IntoIterator for &'a mut [T; 27]
  • impl<'a, T> IntoIterator for &'a [T; 28]
  • impl<'a, T> IntoIterator for &'a mut [T; 28]
  • impl<'a, T> IntoIterator for &'a [T; 29]
  • impl<'a, T> IntoIterator for &'a mut [T; 29]
  • impl<'a, T> IntoIterator for &'a [T; 30]
  • impl<'a, T> IntoIterator for &'a mut [T; 30]
  • impl<'a, T> IntoIterator for &'a [T; 31]
  • impl<'a, T> IntoIterator for &'a mut [T; 31]
  • impl<'a, T> IntoIterator for &'a [T; 32]
  • impl<'a, T> IntoIterator for &'a mut [T; 32]
  • impl<I> IntoIterator for I where I: Iterator
  • impl<T> IntoIterator for Option<T>
  • impl<'a, T> IntoIterator for &'a Option<T>
  • impl<'a, T> IntoIterator for &'a mut Option<T>
  • impl<T, E> IntoIterator for Result<T, E>
  • impl<'a, T, E> IntoIterator for &'a Result<T, E>
  • impl<'a, T, E> IntoIterator for &'a mut Result<T, E>
  • impl<'a, T> IntoIterator for &'a [T]
  • impl<'a, T> IntoIterator for &'a mut [T]
  • impl<T> IntoIterator for BinaryHeap<T> where T: Ord
  • impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord
  • impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> where K: 'a, V: 'a
  • impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> where K: 'a, V: 'a
  • impl<K, V> IntoIterator for BTreeMap<K, V>
  • impl<T> IntoIterator for BTreeSet<T>
  • impl<'a, T> IntoIterator for &'a BTreeSet<T>
  • impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike
  • impl<T> IntoIterator for LinkedList<T>
  • impl<'a, T> IntoIterator for &'a LinkedList<T>
  • impl<'a, T> IntoIterator for &'a mut LinkedList<T>
  • impl<T> IntoIterator for Vec<T>
  • impl<'a, T> IntoIterator for &'a Vec<T>
  • impl<'a, T> IntoIterator for &'a mut Vec<T>
  • impl<T> IntoIterator for VecDeque<T>
  • impl<'a, T> IntoIterator for &'a VecDeque<T>
  • impl<'a, T> IntoIterator for &'a mut VecDeque<T>
  • impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> where K: Eq + Hash, S: BuildHasher
  • impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S> where K: Eq + Hash, S: BuildHasher
  • impl<K, V, S> IntoIterator for HashMap<K, V, S> where K: Eq + Hash, S: BuildHasher
  • impl<'a, T, S> IntoIterator for &'a HashSet<T, S> where T: Eq + Hash, S: BuildHasher
  • impl<T, S> IntoIterator for HashSet<T, S> where T: Eq + Hash, S: BuildHasher
  • impl<'a> IntoIterator for &'a UnixListener
  • impl<'a> IntoIterator for &'a PathBuf
  • impl<'a> IntoIterator for &'a Path
  • impl<'a, T> IntoIterator for &'a Receiver<T>
  • impl<T> IntoIterator for Receiver<T>

Trait std::iter::FromIterator1.0.0 [] [src]

pub trait FromIterator<A> {
    fn from_iter<T>(iter: T) -> Self where T: IntoIterator<Item=A>;
}

Conversion from an Iterator.

By implementing FromIterator for a type, you define how it will be created from an iterator. This is common for types which describe a collection of some kind.

FromIterator's from_iter() is rarely called explicitly, and is instead used through Iterator's collect() method. See collect()'s documentation for more examples.

See also: IntoIterator.

Examples

Basic usage:

fn main() { use std::iter::FromIterator; let five_fives = std::iter::repeat(5).take(5); let v = Vec::from_iter(five_fives); assert_eq!(v, vec![5, 5, 5, 5, 5]); }
use std::iter::FromIterator;

let five_fives = std::iter::repeat(5).take(5);

let v = Vec::from_iter(five_fives);

assert_eq!(v, vec![5, 5, 5, 5, 5]);

Using collect() to implicitly use FromIterator:

fn main() { let five_fives = std::iter::repeat(5).take(5); let v: Vec<i32> = five_fives.collect(); assert_eq!(v, vec![5, 5, 5, 5, 5]); }
let five_fives = std::iter::repeat(5).take(5);

let v: Vec<i32> = five_fives.collect();

assert_eq!(v, vec![5, 5, 5, 5, 5]);

Implementing FromIterator for your type:

fn main() { use std::iter::FromIterator; // A sample collection, that's just a wrapper over Vec<T> #[derive(Debug)] struct MyCollection(Vec<i32>); // Let's give it some methods so we can create one and add things // to it. impl MyCollection { fn new() -> MyCollection { MyCollection(Vec::new()) } fn add(&mut self, elem: i32) { self.0.push(elem); } } // and we'll implement FromIterator impl FromIterator<i32> for MyCollection { fn from_iter<I: IntoIterator<Item=i32>>(iter: I) -> Self { let mut c = MyCollection::new(); for i in iter { c.add(i); } c } } // Now we can make a new iterator... let iter = (0..5).into_iter(); // ... and make a MyCollection out of it let c = MyCollection::from_iter(iter); assert_eq!(c.0, vec![0, 1, 2, 3, 4]); // collect works too! let iter = (0..5).into_iter(); let c: MyCollection = iter.collect(); assert_eq!(c.0, vec![0, 1, 2, 3, 4]); }
use std::iter::FromIterator;

// A sample collection, that's just a wrapper over Vec<T>
#[derive(Debug)]
struct MyCollection(Vec<i32>);

// Let's give it some methods so we can create one and add things
// to it.
impl MyCollection {
    fn new() -> MyCollection {
        MyCollection(Vec::new())
    }

    fn add(&mut self, elem: i32) {
        self.0.push(elem);
    }
}

// and we'll implement FromIterator
impl FromIterator<i32> for MyCollection {
    fn from_iter<I: IntoIterator<Item=i32>>(iter: I) -> Self {
        let mut c = MyCollection::new();

        for i in iter {
            c.add(i);
        }

        c
    }
}

// Now we can make a new iterator...
let iter = (0..5).into_iter();

// ... and make a MyCollection out of it
let c = MyCollection::from_iter(iter);

assert_eq!(c.0, vec![0, 1, 2, 3, 4]);

// collect works too!

let iter = (0..5).into_iter();
let c: MyCollection = iter.collect();

assert_eq!(c.0, vec![0, 1, 2, 3, 4]);

Required Methods

fn from_iter<T>(iter: T) -> Self where T: IntoIterator<Item=A>

Creates a value from an iterator.

See the module-level documentation for more.

Examples

Basic usage:

fn main() { use std::iter::FromIterator; let five_fives = std::iter::repeat(5).take(5); let v = Vec::from_iter(five_fives); assert_eq!(v, vec![5, 5, 5, 5, 5]); }
use std::iter::FromIterator;

let five_fives = std::iter::repeat(5).take(5);

let v = Vec::from_iter(five_fives);

assert_eq!(v, vec![5, 5, 5, 5, 5]);

Implementors

Trait std::cmp::PartialEq1.0.0 [] [src]

pub trait PartialEq<Rhs = Self> where Rhs: ?Sized {
    fn eq(&self, other: &Rhs) -> bool;

    fn ne(&self, other: &Rhs) -> bool { ... }
}

Trait for equality comparisons which are partial equivalence relations.

This trait allows for partial equality, for types that do not have a full equivalence relation. For example, in floating point numbers NaN != NaN, so floating point types implement PartialEq but not Eq.

Formally, the equality must be (for all a, b and c):

  • symmetric: a == b implies b == a; and
  • transitive: a == b and b == c implies a == c.

Note that these requirements mean that the trait itself must be implemented symmetrically and transitively: if T: PartialEq<U> and U: PartialEq<V> then U: PartialEq<T> and T: PartialEq<V>.

Derivable

This trait can be used with #[derive]. When derived on structs, two instances are equal if all fields are equal, and not equal if any fields are not equal. When derived on enums, each variant is equal to itself and not equal to the other variants.

How can I implement PartialEq?

PartialEq only requires the eq method to be implemented; ne is defined in terms of it by default. Any manual implementation of ne must respect the rule that eq is a strict inverse of ne; that is, !(a == b) if and only if a != b.

An example implementation for a domain in which two books are considered the same book if their ISBN matches, even if the formats differ:

fn main() { enum BookFormat { Paperback, Hardback, Ebook } struct Book { isbn: i32, format: BookFormat, } impl PartialEq for Book { fn eq(&self, other: &Book) -> bool { self.isbn == other.isbn } } let b1 = Book { isbn: 3, format: BookFormat::Paperback }; let b2 = Book { isbn: 3, format: BookFormat::Ebook }; let b3 = Book { isbn: 10, format: BookFormat::Paperback }; assert!(b1 == b2); assert!(b1 != b3); }
enum BookFormat { Paperback, Hardback, Ebook }
struct Book {
    isbn: i32,
    format: BookFormat,
}

impl PartialEq for Book {
    fn eq(&self, other: &Book) -> bool {
        self.isbn == other.isbn
    }
}

let b1 = Book { isbn: 3, format: BookFormat::Paperback };
let b2 = Book { isbn: 3, format: BookFormat::Ebook };
let b3 = Book { isbn: 10, format: BookFormat::Paperback };

assert!(b1 == b2);
assert!(b1 != b3);

Examples

fn main() { let x: u32 = 0; let y: u32 = 1; assert_eq!(x == y, false); assert_eq!(x.eq(&y), false); }
let x: u32 = 0;
let y: u32 = 1;

assert_eq!(x == y, false);
assert_eq!(x.eq(&y), false);

Required Methods

fn eq(&self, other: &Rhs) -> bool

This method tests for self and other values to be equal, and is used by ==.

Provided Methods

fn ne(&self, other: &Rhs) -> bool

This method tests for !=.

Implementors

Trait std::cmp::PartialOrd1.0.0 [] [src]

pub trait PartialOrd<Rhs = Self>: PartialEq<Rhs> where Rhs: ?Sized {
    fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;

    fn lt(&self, other: &Rhs) -> bool { ... }
    fn le(&self, other: &Rhs) -> bool { ... }
    fn gt(&self, other: &Rhs) -> bool { ... }
    fn ge(&self, other: &Rhs) -> bool { ... }
}

Trait for values that can be compared for a sort-order.

The comparison must satisfy, for all a, b and c:

  • antisymmetry: if a < b then !(a > b), as well as a > b implying !(a < b); and
  • transitivity: a < b and b < c implies a < c. The same must hold for both == and >.

Note that these requirements mean that the trait itself must be implemented symmetrically and transitively: if T: PartialOrd<U> and U: PartialOrd<V> then U: PartialOrd<T> and T: PartialOrd<V>.

Derivable

This trait can be used with #[derive]. When derived, it will produce a lexicographic ordering based on the top-to-bottom declaration order of the struct's members.

How can I implement Ord?

PartialOrd only requires implementation of the partial_cmp method, with the others generated from default implementations.

However it remains possible to implement the others separately for types which do not have a total order. For example, for floating point numbers, NaN < 0 == false and NaN >= 0 == false (cf. IEEE 754-2008 section 5.11).

PartialOrd requires your type to be PartialEq.

If your type is Ord, you can implement partial_cmp() by using cmp():

fn main() { use std::cmp::Ordering; #[derive(Eq)] struct Person { id: u32, name: String, height: u32, } impl PartialOrd for Person { fn partial_cmp(&self, other: &Person) -> Option<Ordering> { Some(self.cmp(other)) } } impl Ord for Person { fn cmp(&self, other: &Person) -> Ordering { self.height.cmp(&other.height) } } impl PartialEq for Person { fn eq(&self, other: &Person) -> bool { self.height == other.height } } }
use std::cmp::Ordering;

#[derive(Eq)]
struct Person {
    id: u32,
    name: String,
    height: u32,
}

impl PartialOrd for Person {
    fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for Person {
    fn cmp(&self, other: &Person) -> Ordering {
        self.height.cmp(&other.height)
    }
}

impl PartialEq for Person {
    fn eq(&self, other: &Person) -> bool {
        self.height == other.height
    }
}

You may also find it useful to use partial_cmp() on your types fields. Here is an example ofPersontypes who have a floating-pointheight` field that is the only field to be used for sorting:

fn main() { use std::cmp::Ordering; struct Person { id: u32, name: String, height: f64, } impl PartialOrd for Person { fn partial_cmp(&self, other: &Person) -> Option<Ordering> { self.height.partial_cmp(&other.height) } } impl PartialEq for Person { fn eq(&self, other: &Person) -> bool { self.height == other.height } } }
use std::cmp::Ordering;

struct Person {
    id: u32,
    name: String,
    height: f64,
}

impl PartialOrd for Person {
    fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
        self.height.partial_cmp(&other.height)
    }
}

impl PartialEq for Person {
    fn eq(&self, other: &Person) -> bool {
        self.height == other.height
    }
}

Examples

fn main() { let x : u32 = 0; let y : u32 = 1; assert_eq!(x < y, true); assert_eq!(x.lt(&y), true); }
let x : u32 = 0;
let y : u32 = 1;

assert_eq!(x < y, true);
assert_eq!(x.lt(&y), true);

Required Methods

fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>

This method returns an ordering between self and other values if one exists.

Examples

fn main() { use std::cmp::Ordering; let result = 1.0.partial_cmp(&2.0); assert_eq!(result, Some(Ordering::Less)); let result = 1.0.partial_cmp(&1.0); assert_eq!(result, Some(Ordering::Equal)); let result = 2.0.partial_cmp(&1.0); assert_eq!(result, Some(Ordering::Greater)); }
use std::cmp::Ordering;

let result = 1.0.partial_cmp(&2.0);
assert_eq!(result, Some(Ordering::Less));

let result = 1.0.partial_cmp(&1.0);
assert_eq!(result, Some(Ordering::Equal));

let result = 2.0.partial_cmp(&1.0);
assert_eq!(result, Some(Ordering::Greater));

When comparison is impossible:

fn main() { let result = std::f64::NAN.partial_cmp(&1.0); assert_eq!(result, None); }
let result = std::f64::NAN.partial_cmp(&1.0);
assert_eq!(result, None);

Provided Methods

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator.

Examples

fn main() { let result = 1.0 < 2.0; assert_eq!(result, true); let result = 2.0 < 1.0; assert_eq!(result, false); }
let result = 1.0 < 2.0;
assert_eq!(result, true);

let result = 2.0 < 1.0;
assert_eq!(result, false);

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator.

Examples

fn main() { let result = 1.0 <= 2.0; assert_eq!(result, true); let result = 2.0 <= 2.0; assert_eq!(result, true); }
let result = 1.0 <= 2.0;
assert_eq!(result, true);

let result = 2.0 <= 2.0;
assert_eq!(result, true);

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator.

Examples

fn main() { let result = 1.0 > 2.0; assert_eq!(result, false); let result = 2.0 > 2.0; assert_eq!(result, false); }
let result = 1.0 > 2.0;
assert_eq!(result, false);

let result = 2.0 > 2.0;
assert_eq!(result, false);

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator.

Examples

fn main() { let result = 2.0 >= 1.0; assert_eq!(result, true); let result = 2.0 >= 2.0; assert_eq!(result, true); }
let result = 2.0 >= 1.0;
assert_eq!(result, true);

let result = 2.0 >= 2.0;
assert_eq!(result, true);

Implementors

Trait std::cmp::Eq1.0.0 [] [src]

pub trait Eq: PartialEq<Self> { }

Trait for equality comparisons which are equivalence relations.

This means, that in addition to a == b and a != b being strict inverses, the equality must be (for all a, b and c):

  • reflexive: a == a;
  • symmetric: a == b implies b == a; and
  • transitive: a == b and b == c implies a == c.

This property cannot be checked by the compiler, and therefore Eq implies PartialEq, and has no extra methods.

Derivable

This trait can be used with #[derive]. When derived, because Eq has no extra methods, it is only informing the compiler that this is an equivalence relation rather than a partial equivalence relation. Note that the derive strategy requires all fields are PartialEq, which isn't always desired.

How can I implement Eq?

If you cannot use the derive strategy, specify that your type implements Eq, which has no methods:

fn main() { enum BookFormat { Paperback, Hardback, Ebook } struct Book { isbn: i32, format: BookFormat, } impl PartialEq for Book { fn eq(&self, other: &Book) -> bool { self.isbn == other.isbn } } impl Eq for Book {} }
enum BookFormat { Paperback, Hardback, Ebook }
struct Book {
    isbn: i32,
    format: BookFormat,
}
impl PartialEq for Book {
    fn eq(&self, other: &Book) -> bool {
        self.isbn == other.isbn
    }
}
impl Eq for Book {}

Implementors

  • impl<T> Eq for Wrapping<T> where T: Eq
  • impl<T> Eq for NonZero<T> where T: Zeroable + Eq
  • impl<T> Eq for *const T where T: ?Sized
  • impl<T> Eq for *mut T where T: ?Sized
  • impl<Ret> Eq for fn() -> Ret
  • impl<Ret> Eq for extern fn() -> Ret
  • impl<Ret> Eq for unsafe fn() -> Ret
  • impl<Ret> Eq for unsafe extern fn() -> Ret
  • impl<Ret, A> Eq for fn(A) -> Ret
  • impl<Ret, A> Eq for extern fn(A) -> Ret
  • impl<Ret, A> Eq for unsafe fn(A) -> Ret
  • impl<Ret, A> Eq for unsafe extern fn(A) -> Ret
  • impl<Ret, A, B> Eq for fn(A, B) -> Ret
  • impl<Ret, A, B> Eq for extern fn(A, B) -> Ret
  • impl<Ret, A, B> Eq for unsafe fn(A, B) -> Ret
  • impl<Ret, A, B> Eq for unsafe extern fn(A, B) -> Ret
  • impl<Ret, A, B, C> Eq for fn(A, B, C) -> Ret
  • impl<Ret, A, B, C> Eq for extern fn(A, B, C) -> Ret
  • impl<Ret, A, B, C> Eq for unsafe fn(A, B, C) -> Ret
  • impl<Ret, A, B, C> Eq for unsafe extern fn(A, B, C) -> Ret
  • impl<Ret, A, B, C, D> Eq for fn(A, B, C, D) -> Ret
  • impl<Ret, A, B, C, D> Eq for extern fn(A, B, C, D) -> Ret
  • impl<Ret, A, B, C, D> Eq for unsafe fn(A, B, C, D) -> Ret
  • impl<Ret, A, B, C, D> Eq for unsafe extern fn(A, B, C, D) -> Ret
  • impl<Ret, A, B, C, D, E> Eq for fn(A, B, C, D, E) -> Ret
  • impl<Ret, A, B, C, D, E> Eq for extern fn(A, B, C, D, E) -> Ret
  • impl<Ret, A, B, C, D, E> Eq for unsafe fn(A, B, C, D, E) -> Ret
  • impl<Ret, A, B, C, D, E> Eq for unsafe extern fn(A, B, C, D, E) -> Ret
  • impl<Ret, A, B, C, D, E, F> Eq for fn(A, B, C, D, E, F) -> Ret
  • impl<Ret, A, B, C, D, E, F> Eq for extern fn(A, B, C, D, E, F) -> Ret
  • impl<Ret, A, B, C, D, E, F> Eq for unsafe fn(A, B, C, D, E, F) -> Ret
  • impl<Ret, A, B, C, D, E, F> Eq for unsafe extern fn(A, B, C, D, E, F) -> Ret
  • impl<Ret, A, B, C, D, E, F, G> Eq for fn(A, B, C, D, E, F, G) -> Ret
  • impl<Ret, A, B, C, D, E, F, G> Eq for extern fn(A, B, C, D, E, F, G) -> Ret
  • impl<Ret, A, B, C, D, E, F, G> Eq for unsafe fn(A, B, C, D, E, F, G) -> Ret
  • impl<Ret, A, B, C, D, E, F, G> Eq for unsafe extern fn(A, B, C, D, E, F, G) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H> Eq for fn(A, B, C, D, E, F, G, H) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H> Eq for extern fn(A, B, C, D, E, F, G, H) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe fn(A, B, C, D, E, F, G, H) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H> Eq for unsafe extern fn(A, B, C, D, E, F, G, H) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I> Eq for fn(A, B, C, D, E, F, G, H, I) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I> Eq for extern fn(A, B, C, D, E, F, G, H, I) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I> Eq for unsafe fn(A, B, C, D, E, F, G, H, I) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I> Eq for unsafe extern fn(A, B, C, D, E, F, G, H, I) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for fn(A, B, C, D, E, F, G, H, I, J) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for extern fn(A, B, C, D, E, F, G, H, I, J) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for unsafe fn(A, B, C, D, E, F, G, H, I, J) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J> Eq for unsafe extern fn(A, B, C, D, E, F, G, H, I, J) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for extern fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for unsafe fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Eq for unsafe extern fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for extern fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for unsafe fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Eq for unsafe extern fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret
  • impl<T> Eq for PhantomData<T> where T: ?Sized
  • impl Eq for RangeFull
  • impl<Idx> Eq for Range<Idx> where Idx: Eq
  • impl<Idx> Eq for RangeFrom<Idx> where Idx: Eq
  • impl<Idx> Eq for RangeTo<Idx> where Idx: Eq
  • impl<Idx> Eq for RangeInclusive<Idx> where Idx: Eq
  • impl<Idx> Eq for RangeToInclusive<Idx> where Idx: Eq
  • impl Eq for Ordering
  • impl Eq for ()
  • impl Eq for bool
  • impl Eq for char
  • impl Eq for usize
  • impl Eq for u8
  • impl Eq for u16
  • impl Eq for u32
  • impl Eq for u64
  • impl Eq for isize
  • impl Eq for i8
  • impl Eq for i16
  • impl Eq for i32
  • impl Eq for i64
  • impl<'a, A> Eq for &'a A where A: Eq + ?Sized
  • impl<'a, A> Eq for &'a mut A where A: Eq + ?Sized
  • impl Eq for TypeId
  • impl<T> Eq for [T; 0] where T: Eq
  • impl<T> Eq for [T; 1] where T: Eq
  • impl<T> Eq for [T; 2] where T: Eq
  • impl<T> Eq for [T; 3] where T: Eq
  • impl<T> Eq for [T; 4] where T: Eq
  • impl<T> Eq for [T; 5] where T: Eq
  • impl<T> Eq for [T; 6] where T: Eq
  • impl<T> Eq for [T; 7] where T: Eq
  • impl<T> Eq for [T; 8] where T: Eq
  • impl<T> Eq for [T; 9] where T: Eq
  • impl<T> Eq for [T; 10] where T: Eq
  • impl<T> Eq for [T; 11] where T: Eq
  • impl<T> Eq for [T; 12] where T: Eq
  • impl<T> Eq for [T; 13] where T: Eq
  • impl<T> Eq for [T; 14] where T: Eq
  • impl<T> Eq for [T; 15] where T: Eq
  • impl<T> Eq for [T; 16] where T: Eq
  • impl<T> Eq for [T; 17] where T: Eq
  • impl<T> Eq for [T; 18] where T: Eq
  • impl<T> Eq for [T; 19] where T: Eq
  • impl<T> Eq for [T; 20] where T: Eq
  • impl<T> Eq for [T; 21] where T: Eq
  • impl<T> Eq for [T; 22] where T: Eq
  • impl<T> Eq for [T; 23] where T: Eq
  • impl<T> Eq for [T; 24] where T: Eq
  • impl<T> Eq for [T; 25] where T: Eq
  • impl<T> Eq for [T; 26] where T: Eq
  • impl<T> Eq for [T; 27] where T: Eq
  • impl<T> Eq for [T; 28] where T: Eq
  • impl<T> Eq for [T; 29] where T: Eq
  • impl<T> Eq for [T; 30] where T: Eq
  • impl<T> Eq for [T; 31] where T: Eq
  • impl<T> Eq for [T; 32] where T: Eq
  • impl<T> Eq for Cell<T> where T: Copy + Eq
  • impl Eq for BorrowState
  • impl<T> Eq for RefCell<T> where T: Eq + ?Sized
  • impl<T> Eq for Option<T> where T: Eq
  • impl<T, E> Eq for Result<T, E> where E: Eq, T: Eq
  • impl<T> Eq for [T] where T: Eq
  • impl Eq for SearchStep
  • impl Eq for Utf8Error
  • impl Eq for str
  • impl Eq for Error
  • impl<A> Eq for (A,) where A: Eq
  • impl<A, B> Eq for (A, B) where A: Eq, B: Eq
  • impl<A, B, C> Eq for (A, B, C) where A: Eq, B: Eq, C: Eq
  • impl<A, B, C, D> Eq for (A, B, C, D) where A: Eq, B: Eq, C: Eq, D: Eq
  • impl<A, B, C, D, E> Eq for (A, B, C, D, E) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq
  • impl<A, B, C, D, E, F> Eq for (A, B, C, D, E, F) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq
  • impl<A, B, C, D, E, F, G> Eq for (A, B, C, D, E, F, G) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq
  • impl<A, B, C, D, E, F, G, H> Eq for (A, B, C, D, E, F, G, H) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq
  • impl<A, B, C, D, E, F, G, H, I> Eq for (A, B, C, D, E, F, G, H, I) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq
  • impl<A, B, C, D, E, F, G, H, I, J> Eq for (A, B, C, D, E, F, G, H, I, J) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq
  • impl<A, B, C, D, E, F, G, H, I, J, K> Eq for (A, B, C, D, E, F, G, H, I, J, K) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq, K: Eq
  • impl<A, B, C, D, E, F, G, H, I, J, K, L> Eq for (A, B, C, D, E, F, G, H, I, J, K, L) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq, F: Eq, G: Eq, H: Eq, I: Eq, J: Eq, K: Eq, L: Eq
  • impl<T> Eq for Box<T> where T: Eq + ?Sized
  • impl<T> Eq for Arc<T> where T: Eq + ?Sized
  • impl<T> Eq for Rc<T> where T: Eq + ?Sized
  • impl<K, V> Eq for BTreeMap<K, V> where K: Eq, V: Eq
  • impl<T> Eq for BTreeSet<T> where T: Eq
  • impl<'a, B> Eq for Cow<'a, B> where B: Eq + ToOwned + ?Sized
  • impl<E> Eq for EnumSet<E> where E: Eq
  • impl<A> Eq for LinkedList<A> where A: Eq
  • impl Eq for String
  • impl Eq for ParseError
  • impl<T> Eq for Vec<T> where T: Eq
  • impl<A> Eq for VecDeque<A> where A: Eq
  • impl<T> Eq for Bound<T> where T: Eq
  • impl Eq for DecodeUtf16Error
  • impl Eq for LocalKeyState
  • impl<K, V, S> Eq for HashMap<K, V, S> where K: Eq + Hash, V: Eq, S: BuildHasher
  • impl<T, S> Eq for HashSet<T, S> where T: Eq + Hash, S: BuildHasher
  • impl Eq for VarError
  • impl Eq for CString
  • impl Eq for CStr
  • impl Eq for OsString
  • impl Eq for OsStr
  • impl Eq for Permissions
  • impl Eq for FileType
  • impl Eq for ErrorKind
  • impl Eq for SeekFrom
  • impl Eq for IpAddr
  • impl Eq for Ipv6MulticastScope
  • impl Eq for Ipv4Addr
  • impl Eq for Ipv6Addr
  • impl Eq for SocketAddr
  • impl Eq for SocketAddrV4
  • impl Eq for SocketAddrV6
  • impl<'a> Eq for Prefix<'a>
  • impl<'a> Eq for PrefixComponent<'a>
  • impl<'a> Eq for Component<'a>
  • impl<'a> Eq for Components<'a>
  • impl Eq for PathBuf
  • impl Eq for StripPrefixError
  • impl Eq for Path
  • impl Eq for Output
  • impl Eq for ExitStatus
  • impl<T: Eq> Eq for SendError<T>
  • impl Eq for RecvError
  • impl Eq for TryRecvError
  • impl Eq for RecvTimeoutError
  • impl<T: Eq> Eq for TrySendError<T>
  • impl Eq for WaitTimeoutResult
  • impl Eq for Duration
  • impl Eq for Instant
  • impl Eq for SystemTime

Trait std::cmp::Ord1.0.0 [] [src]

pub trait Ord: Eq + PartialOrd<Self> {
    fn cmp(&self, other: &Self) -> Ordering;
}

Trait for types that form a total order.

An order is a total order if it is (for all a, b and c):

  • total and antisymmetric: exactly one of a < b, a == b or a > b is true; and
  • transitive, a < b and b < c implies a < c. The same must hold for both == and >.

Derivable

This trait can be used with #[derive]. When derived, it will produce a lexicographic ordering based on the top-to-bottom declaration order of the struct's members.

How can I implement Ord?

Ord requires that the type also be PartialOrd and Eq (which requires PartialEq).

Then you must define an implementation for cmp(). You may find it useful to use cmp() on your type's fields.

Here's an example where you want to sort people by height only, disregarding id and name:

fn main() { use std::cmp::Ordering; #[derive(Eq)] struct Person { id: u32, name: String, height: u32, } impl Ord for Person { fn cmp(&self, other: &Person) -> Ordering { self.height.cmp(&other.height) } } impl PartialOrd for Person { fn partial_cmp(&self, other: &Person) -> Option<Ordering> { Some(self.cmp(other)) } } impl PartialEq for Person { fn eq(&self, other: &Person) -> bool { self.height == other.height } } }
use std::cmp::Ordering;

#[derive(Eq)]
struct Person {
    id: u32,
    name: String,
    height: u32,
}

impl Ord for Person {
    fn cmp(&self, other: &Person) -> Ordering {
        self.height.cmp(&other.height)
    }
}

impl PartialOrd for Person {
    fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl PartialEq for Person {
    fn eq(&self, other: &Person) -> bool {
        self.height == other.height
    }
}

Required Methods

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other.

By convention, self.cmp(&other) returns the ordering matching the expression self <operator> other if true.

Examples

fn main() { use std::cmp::Ordering; assert_eq!(5.cmp(&10), Ordering::Less); assert_eq!(10.cmp(&5), Ordering::Greater); assert_eq!(5.cmp(&5), Ordering::Equal); }
use std::cmp::Ordering;

assert_eq!(5.cmp(&10), Ordering::Less);
assert_eq!(10.cmp(&5), Ordering::Greater);
assert_eq!(5.cmp(&5), Ordering::Equal);

Implementors

  • impl<T> Ord for Wrapping<T> where T: Ord
  • impl<T> Ord for NonZero<T> where T: Zeroable + Ord
  • impl<Ret> Ord for fn() -> Ret
  • impl<Ret> Ord for extern fn() -> Ret
  • impl<Ret> Ord for unsafe fn() -> Ret
  • impl<Ret> Ord for unsafe extern fn() -> Ret
  • impl<Ret, A> Ord for fn(A) -> Ret
  • impl<Ret, A> Ord for extern fn(A) -> Ret
  • impl<Ret, A> Ord for unsafe fn(A) -> Ret
  • impl<Ret, A> Ord for unsafe extern fn(A) -> Ret
  • impl<Ret, A, B> Ord for fn(A, B) -> Ret
  • impl<Ret, A, B> Ord for extern fn(A, B) -> Ret
  • impl<Ret, A, B> Ord for unsafe fn(A, B) -> Ret
  • impl<Ret, A, B> Ord for unsafe extern fn(A, B) -> Ret
  • impl<Ret, A, B, C> Ord for fn(A, B, C) -> Ret
  • impl<Ret, A, B, C> Ord for extern fn(A, B, C) -> Ret
  • impl<Ret, A, B, C> Ord for unsafe fn(A, B, C) -> Ret
  • impl<Ret, A, B, C> Ord for unsafe extern fn(A, B, C) -> Ret
  • impl<Ret, A, B, C, D> Ord for fn(A, B, C, D) -> Ret
  • impl<Ret, A, B, C, D> Ord for extern fn(A, B, C, D) -> Ret
  • impl<Ret, A, B, C, D> Ord for unsafe fn(A, B, C, D) -> Ret
  • impl<Ret, A, B, C, D> Ord for unsafe extern fn(A, B, C, D) -> Ret
  • impl<Ret, A, B, C, D, E> Ord for fn(A, B, C, D, E) -> Ret
  • impl<Ret, A, B, C, D, E> Ord for extern fn(A, B, C, D, E) -> Ret
  • impl<Ret, A, B, C, D, E> Ord for unsafe fn(A, B, C, D, E) -> Ret
  • impl<Ret, A, B, C, D, E> Ord for unsafe extern fn(A, B, C, D, E) -> Ret
  • impl<Ret, A, B, C, D, E, F> Ord for fn(A, B, C, D, E, F) -> Ret
  • impl<Ret, A, B, C, D, E, F> Ord for extern fn(A, B, C, D, E, F) -> Ret
  • impl<Ret, A, B, C, D, E, F> Ord for unsafe fn(A, B, C, D, E, F) -> Ret
  • impl<Ret, A, B, C, D, E, F> Ord for unsafe extern fn(A, B, C, D, E, F) -> Ret
  • impl<Ret, A, B, C, D, E, F, G> Ord for fn(A, B, C, D, E, F, G) -> Ret
  • impl<Ret, A, B, C, D, E, F, G> Ord for extern fn(A, B, C, D, E, F, G) -> Ret
  • impl<Ret, A, B, C, D, E, F, G> Ord for unsafe fn(A, B, C, D, E, F, G) -> Ret
  • impl<Ret, A, B, C, D, E, F, G> Ord for unsafe extern fn(A, B, C, D, E, F, G) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H> Ord for fn(A, B, C, D, E, F, G, H) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H> Ord for extern fn(A, B, C, D, E, F, G, H) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H> Ord for unsafe fn(A, B, C, D, E, F, G, H) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H> Ord for unsafe extern fn(A, B, C, D, E, F, G, H) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I> Ord for fn(A, B, C, D, E, F, G, H, I) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I> Ord for extern fn(A, B, C, D, E, F, G, H, I) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I> Ord for unsafe fn(A, B, C, D, E, F, G, H, I) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I> Ord for unsafe extern fn(A, B, C, D, E, F, G, H, I) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J> Ord for fn(A, B, C, D, E, F, G, H, I, J) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J> Ord for extern fn(A, B, C, D, E, F, G, H, I, J) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J> Ord for unsafe fn(A, B, C, D, E, F, G, H, I, J) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J> Ord for unsafe extern fn(A, B, C, D, E, F, G, H, I, J) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Ord for fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Ord for extern fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Ord for unsafe fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K> Ord for unsafe extern fn(A, B, C, D, E, F, G, H, I, J, K) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Ord for fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Ord for extern fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Ord for unsafe fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret
  • impl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Ord for unsafe extern fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Ret
  • impl<T> Ord for *const T where T: ?Sized
  • impl<T> Ord for *mut T where T: ?Sized
  • impl<T> Ord for PhantomData<T> where T: ?Sized
  • impl Ord for Ordering
  • impl Ord for ()
  • impl Ord for bool
  • impl Ord for char
  • impl Ord for usize
  • impl Ord for u8
  • impl Ord for u16
  • impl Ord for u32
  • impl Ord for u64
  • impl Ord for isize
  • impl Ord for i8
  • impl Ord for i16
  • impl Ord for i32
  • impl Ord for i64
  • impl<'a, A> Ord for &'a A where A: Ord + ?Sized
  • impl<'a, A> Ord for &'a mut A where A: Ord + ?Sized
  • impl<T> Ord for [T; 0] where T: Ord
  • impl<T> Ord for [T; 1] where T: Ord
  • impl<T> Ord for [T; 2] where T: Ord
  • impl<T> Ord for [T; 3] where T: Ord
  • impl<T> Ord for [T; 4] where T: Ord
  • impl<T> Ord for [T; 5] where T: Ord
  • impl<T> Ord for [T; 6] where T: Ord
  • impl<T> Ord for [T; 7] where T: Ord
  • impl<T> Ord for [T; 8] where T: Ord
  • impl<T> Ord for [T; 9] where T: Ord
  • impl<T> Ord for [T; 10] where T: Ord
  • impl<T> Ord for [T; 11] where T: Ord
  • impl<T> Ord for [T; 12] where T: Ord
  • impl<T> Ord for [T; 13] where T: Ord
  • impl<T> Ord for [T; 14] where T: Ord
  • impl<T> Ord for [T; 15] where T: Ord
  • impl<T> Ord for [T; 16] where T: Ord
  • impl<T> Ord for [T; 17] where T: Ord
  • impl<T> Ord for [T; 18] where T: Ord
  • impl<T> Ord for [T; 19] where T: Ord
  • impl<T> Ord for [T; 20] where T: Ord
  • impl<T> Ord for [T; 21] where T: Ord
  • impl<T> Ord for [T; 22] where T: Ord
  • impl<T> Ord for [T; 23] where T: Ord
  • impl<T> Ord for [T; 24] where T: Ord
  • impl<T> Ord for [T; 25] where T: Ord
  • impl<T> Ord for [T; 26] where T: Ord
  • impl<T> Ord for [T; 27] where T: Ord
  • impl<T> Ord for [T; 28] where T: Ord
  • impl<T> Ord for [T; 29] where T: Ord
  • impl<T> Ord for [T; 30] where T: Ord
  • impl<T> Ord for [T; 31] where T: Ord
  • impl<T> Ord for [T; 32] where T: Ord
  • impl<T> Ord for Cell<T> where T: Copy + Ord
  • impl<T> Ord for RefCell<T> where T: Ord + ?Sized
  • impl<T> Ord for Option<T> where T: Ord
  • impl<T, E> Ord for Result<T, E> where E: Ord, T: Ord
  • impl<T> Ord for [T] where T: Ord
  • impl Ord for str
  • impl Ord for Error
  • impl<A> Ord for (A,) where A: Ord
  • impl<A, B> Ord for (A, B) where A: Ord, B: Ord
  • impl<A, B, C> Ord for (A, B, C) where A: Ord, B: Ord, C: Ord
  • impl<A, B, C, D> Ord for (A, B, C, D) where A: Ord, B: Ord, C: Ord, D: Ord
  • impl<A, B, C, D, E> Ord for (A, B, C, D, E) where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord
  • impl<A, B, C, D, E, F> Ord for (A, B, C, D, E, F) where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord, F: Ord
  • impl<A, B, C, D, E, F, G> Ord for (A, B, C, D, E, F, G) where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord, F: Ord, G: Ord
  • impl<A, B, C, D, E, F, G, H> Ord for (A, B, C, D, E, F, G, H) where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord, F: Ord, G: Ord, H: Ord
  • impl<A, B, C, D, E, F, G, H, I> Ord for (A, B, C, D, E, F, G, H, I) where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord, F: Ord, G: Ord, H: Ord, I: Ord
  • impl<A, B, C, D, E, F, G, H, I, J> Ord for (A, B, C, D, E, F, G, H, I, J) where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord, F: Ord, G: Ord, H: Ord, I: Ord, J: Ord
  • impl<A, B, C, D, E, F, G, H, I, J, K> Ord for (A, B, C, D, E, F, G, H, I, J, K) where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord, F: Ord, G: Ord, H: Ord, I: Ord, J: Ord, K: Ord
  • impl<A, B, C, D, E, F, G, H, I, J, K, L> Ord for (A, B, C, D, E, F, G, H, I, J, K, L) where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord, F: Ord, G: Ord, H: Ord, I: Ord, J: Ord, K: Ord, L: Ord
  • impl<T> Ord for Box<T> where T: Ord + ?Sized
  • impl<T> Ord for Arc<T> where T: Ord + ?Sized
  • impl<T> Ord for Rc<T> where T: Ord + ?Sized
  • impl<K, V> Ord for BTreeMap<K, V> where K: Ord, V: Ord
  • impl<T> Ord for BTreeSet<T> where T: Ord
  • impl<'a, B> Ord for Cow<'a, B> where B: Ord + ToOwned + ?Sized
  • impl<E> Ord for EnumSet<E> where E: Ord
  • impl<A> Ord for LinkedList<A> where A: Ord
  • impl Ord for String
  • impl<T> Ord for Vec<T> where T: Ord
  • impl<A> Ord for VecDeque<A> where A: Ord
  • impl Ord for CString
  • impl Ord for CStr
  • impl Ord for OsString
  • impl Ord for OsStr
  • impl Ord for IpAddr
  • impl Ord for Ipv4Addr
  • impl Ord for Ipv6Addr
  • impl<'a> Ord for Prefix<'a>
  • impl<'a> Ord for PrefixComponent<'a>
  • impl<'a> Ord for Component<'a>
  • impl<'a> Ord for Components<'a>
  • impl Ord for PathBuf
  • impl Ord for Path
  • impl Ord for Duration
  • impl Ord for Instant
  • impl Ord for SystemTime

Trait std::io::Write1.0.0 [] [src]

pub trait Write {
    fn write(&mut self, buf: &[u8]) -> Result<usize>;
    fn flush(&mut self) -> Result<()>;

    fn write_all(&mut self, buf: &[u8]) -> Result<()> { ... }
    fn