pub struct VecChain<T> { /* private fields */ }
Implementations§
Source§impl<T> VecChain<T>
impl<T> VecChain<T>
Sourcepub unsafe fn from_raw_parts(
ptr: *mut T,
length: usize,
capacity: usize,
) -> Self
pub unsafe fn from_raw_parts( ptr: *mut T, length: usize, capacity: usize, ) -> Self
§Safety
You must uphold all safety requirements that Vec::from_raw_parts
has.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new vec chain, and preallocate some memory
The amount of memory allocated will be at least enough to hold capacity
elements without reallocating. No allocation will happen if the provided
capacity is zero, or if T
is a ZST.
There is NO GUARANTEE that this function will allocate an exact amount
of memory, so do not rely on this for soundness. If knowing the actual
allocated capacity is important, always do so using the
capacity
function.
If the element type (ie. T
) is a ZST, the vec chain will never
allocate, and will always have a capacity of usize::MAX
bytes.
§Panics
Panics if the new capacity exceeds isize::MAX
bytes (not elements,
bytes). This is the same behaviour of Vec::with_capacity
.
§Examples
let chain = VecChain::with_capacity(10)
// chaining methods to get the len and capacity of the vec chain
.len(&mut len)
.capacity(&mut initial_capacity);
// The vector chain contains zero elements, and at least room for 10 more
assert_eq!(len, 0);
assert!(initial_capacity >= 10);
// These are all done without reallocating
let chain = (0..10)
.fold(chain, |chain, i| chain.push(i))
.len(&mut len)
.capacity(&mut capacity);
assert_eq!(len, 10);
assert_eq!(capacity, initial_capacity);
// Now however, pushing another element can make the vector reallocate
let chain = chain
.push(11)
.len(&mut len)
.capacity(&mut capacity);
assert_eq!(len, 11);
assert!(capacity >= 11);
// ZSTs never allocate and always have a capacity of `usize::MAX`
let chain1 = VecChain::<()>::new()
.capacity(&mut capacity1);
let chain2 = VecChain::<()>::with_capacity(10)
.capacity(&mut capacity2);
assert_eq!(capacity1, usize::MAX);
assert_eq!(capacity2, usize::MAX);
Source§impl<T> VecChain<T>
impl<T> VecChain<T>
Sourcepub fn append<I>(self, other: &mut I) -> Selfwhere
I: AsChainInner<Vec<T>>,
pub fn append<I>(self, other: &mut I) -> Selfwhere
I: AsChainInner<Vec<T>>,
Takes and moves all elements from another Vec
or VecChain
into self
, leaving it empty.
§Examples
TODO
pub fn binary_search<O>(self, x: &T, out: O) -> Self
pub fn binary_search_by<O, F>( self, f: F, out: &mut Result<usize, usize>, ) -> Self
pub fn binary_search_by_key<B, O, F>(self, b: &B, f: F, out: O) -> Self
pub fn capacity<O>(self, out: O) -> Selfwhere
O: OutputStorage<usize>,
pub fn clear(self) -> Self
pub fn clone_from_slice(self, src: &[T]) -> Selfwhere
T: Clone,
pub fn copy_from_slice(self, src: &[T]) -> Selfwhere
T: Copy,
pub fn contains<O>(self, x: &T, out: O) -> Self
pub fn dedup(self) -> Selfwhere
T: PartialOrd,
pub fn dedup_by<F>(self, same_bucket: F) -> Self
pub fn dedup_by_key<K, F>(self, key: F) -> Self
pub fn ends_with<O>(self, needle: &[T], out: O) -> Self
pub fn fill(self, value: T) -> Selfwhere
T: Clone,
pub fn fill_with<F>(self, f: F) -> Selfwhere
F: FnMut() -> T,
pub fn insert(self, index: usize, element: T) -> Self
pub fn len<O>(self, out: O) -> Selfwhere
O: OutputStorage<usize>,
pub fn push(self, value: T) -> Self
pub fn remove<O>(self, index: usize, out: O) -> Selfwhere
O: OutputStorage<T>,
pub fn reserve(self, additional: usize) -> Self
pub fn reserve_exact(self, additional: usize) -> Self
Trait Implementations§
Source§impl<T> AsChainInner<Vec<T>> for VecChain<T>
impl<T> AsChainInner<Vec<T>> for VecChain<T>
Source§impl<T> Chain for VecChain<T>
impl<T> Chain for VecChain<T>
Source§impl<T> PartialOrd<Vec<T>> for VecChain<T>
impl<T> PartialOrd<Vec<T>> for VecChain<T>
Source§impl<T> PartialOrd<VecChain<T>> for Vec<T>
impl<T> PartialOrd<VecChain<T>> for Vec<T>
Source§impl<T> PartialOrd for VecChain<T>
impl<T> PartialOrd for VecChain<T>
impl<T> Copy for VecChain<T>
Auto Trait Implementations§
impl<T> Freeze for VecChain<T>
impl<T> RefUnwindSafe for VecChain<T>where
T: RefUnwindSafe,
impl<T> Send for VecChain<T>where
T: Send,
impl<T> Sync for VecChain<T>where
T: Sync,
impl<T> Unpin for VecChain<T>where
T: Unpin,
impl<T> UnwindSafe for VecChain<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)