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

Create a new empty instance.

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)

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);

Returns true if the vector contains no elements.

Examples

let mut v = Vec::new();
assert!(v.is_empty());

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Performs the conversion.

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

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.