Struct opening_hours_syntax::sorted_vec::UniqueSortedVec [−][src]
#[repr(transparent)]pub struct UniqueSortedVec<T>(_);
Expand description
A wrapper arround a Vec
that is always sorted and with values repeating
at most once.
use opening_hours_syntax::sorted_vec::UniqueSortedVec; let sorted: UniqueSortedVec<_> = vec![2, 1, 3, 5, 3].into(); assert_eq!(sorted.as_slice(), &[1, 2, 3, 5]);
Implementations
Build a new UniqueSortedVec
with borrowed content. The order is
assumed to be equivalent for borrowed content.
use opening_hours_syntax::sorted_vec::UniqueSortedVec; let sorted: UniqueSortedVec<_> = vec!["Hello".to_string(), "Anaïs".to_string()].into(); let sorted_ref: UniqueSortedVec<&str> = sorted.to_ref(); assert_eq!(sorted_ref.as_slice(), &["Anaïs", "Hello"]);
Merge values of two UniqueSortedVec
while preserving the invariants.
use opening_hours_syntax::sorted_vec::UniqueSortedVec; let sorted_1: UniqueSortedVec<_> = vec![1, 2, 3].into(); let sorted_2: UniqueSortedVec<_> = vec![0, 3, 4].into(); assert_eq!(sorted_1.union(sorted_2).as_slice(), &[0, 1, 2, 3, 4]);
Returns true if the slice contains an element with the given value.
use opening_hours_syntax::sorted_vec::UniqueSortedVec; let sorted: UniqueSortedVec<_> = vec![10, 40, 30].into(); assert!(sorted.contains(&30)); assert!(!sorted.contains(&50));
Search for the given value in the slice return a reference to it or the next greater value if it is not found.
use opening_hours_syntax::sorted_vec::UniqueSortedVec; let sorted: UniqueSortedVec<_> = vec![10, 40, 30].into(); assert_eq!(sorted.find_first_following(&30), Some(&30)); assert_eq!(sorted.find_first_following(&31), Some(&40)); assert_eq!(sorted.find_first_following(&50), None);
Methods from Deref<Target = Vec<T>>
Returns the number of elements the vector can hold without reallocating.
Examples
let vec: Vec<i32> = Vec::with_capacity(10); assert_eq!(vec.capacity(), 10);
Extracts a slice containing the entire vector.
Equivalent to &s[..]
.
Examples
use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap();
Returns a raw pointer to the vector’s buffer.
The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.
The caller must also ensure that the memory the pointer (non-transitively) points to
is never written to (except inside an UnsafeCell
) using this pointer or any pointer
derived from it. If you need to mutate the contents of the slice, use as_mut_ptr
.
Examples
let x = vec![1, 2, 4]; let x_ptr = x.as_ptr(); unsafe { for i in 0..x.len() { assert_eq!(*x_ptr.add(i), 1 << i); } }
🔬 This is a nightly-only experimental API. (allocator_api
)
allocator_api
)Returns a reference to the underlying allocator.
Returns the number of elements in the vector, also referred to as its ‘length’.
Examples
let a = vec![1, 2, 3]; assert_eq!(a.len(), 3);
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for UniqueSortedVec<T> where
T: RefUnwindSafe,
impl<T> Send for UniqueSortedVec<T> where
T: Send,
impl<T> Sync for UniqueSortedVec<T> where
T: Sync,
impl<T> Unpin for UniqueSortedVec<T> where
T: Unpin,
impl<T> UnwindSafe for UniqueSortedVec<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more