wiwi::chain

Struct VecChain

Source
pub struct VecChain<T> { /* private fields */ }

Implementations§

Source§

impl<T> VecChain<T>

Source

pub fn new() -> Self

Creates a new vector chain without allocating any capacity

It will not allocate until it needs to, either by pushing an element, calling the reserve function to explicitly request allocation, or something else.

§Examples
// a chain thingie! yay!...
let chain = VecChain::new();
Source

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.

Source

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>

Source

pub fn append<I>(self, other: &mut I) -> Self
where I: AsChainInner<Vec<T>>,

Takes and moves all elements from another Vec or VecChain into self, leaving it empty.

§Examples

TODO

Source

pub fn binary_search_by<O, F>( self, f: F, out: &mut Result<usize, usize>, ) -> Self

Source

pub fn binary_search_by_key<B, O, F>(self, b: &B, f: F, out: O) -> Self
where B: Ord, F: FnMut(&T) -> B, O: OutputStorage<Result<usize, usize>>,

Source

pub fn capacity<O>(self, out: O) -> Self
where O: OutputStorage<usize>,

Source

pub fn clear(self) -> Self

Source

pub fn clone_from_slice(self, src: &[T]) -> Self
where T: Clone,

Source

pub fn copy_from_slice(self, src: &[T]) -> Self
where T: Copy,

Source

pub fn contains<O>(self, x: &T, out: O) -> Self

Source

pub fn dedup(self) -> Self
where T: PartialOrd,

Source

pub fn dedup_by<F>(self, same_bucket: F) -> Self
where F: FnMut(&mut T, &mut T) -> bool,

Source

pub fn dedup_by_key<K, F>(self, key: F) -> Self
where F: FnMut(&mut T) -> K, K: PartialEq,

Source

pub fn ends_with<O>(self, needle: &[T], out: O) -> Self

Source

pub fn fill(self, value: T) -> Self
where T: Clone,

Source

pub fn fill_with<F>(self, f: F) -> Self
where F: FnMut() -> T,

Source

pub fn insert(self, index: usize, element: T) -> Self

Source

pub fn len<O>(self, out: O) -> Self
where O: OutputStorage<usize>,

Source

pub fn push(self, value: T) -> Self

Source

pub fn remove<O>(self, index: usize, out: O) -> Self
where O: OutputStorage<T>,

Source

pub fn reserve(self, additional: usize) -> Self

Source

pub fn reserve_exact(self, additional: usize) -> Self

Source

pub unsafe fn set_len(self, new_len: usize) -> Self

§Safety

new_len must be less than or equal to capacity, and the first new_len elements must be initialised/

Trait Implementations§

Source§

impl<T> AsChainInner<Vec<T>> for VecChain<T>

Source§

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

Source§

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

Source§

impl<T> AsMut<Vec<T>> for VecChain<T>

Source§

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

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

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

Source§

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

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Chain for VecChain<T>

Source§

type Inner = Vec<T>

Source§

fn into_inner(self) -> Self::Inner

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn as_inner(&self) -> &Self::Inner

Source§

fn as_inner_mut(&mut self) -> &mut Self::Inner

Source§

fn with_inner<F, Void>(self, f: F) -> Self
where F: FnOnce(&mut Self::Inner) -> Void,

Takes a closure that is called, passing in a reference to the inner value Read more
Source§

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

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Default for VecChain<T>
where Vec<T>: Default,

Source§

fn default() -> Self

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

impl<T> Display for VecChain<T>
where Vec<T>: Display,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> From<&Vec<T>> for VecChain<T>
where Vec<T>: Clone,

Source§

fn from(inner: &Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<&VecChain<T>> for Vec<T>
where Vec<T>: Clone,

Source§

fn from(chain: &VecChain<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<&mut Vec<T>> for VecChain<T>
where Vec<T>: Clone,

Source§

fn from(inner: &mut Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<&mut VecChain<T>> for Vec<T>
where Vec<T>: Clone,

Source§

fn from(chain: &mut VecChain<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for VecChain<T>

Source§

fn from(inner: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<VecChain<T>> for Vec<T>

Source§

fn from(chain: VecChain<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> PartialEq<Vec<T>> for VecChain<T>
where Vec<T>: PartialEq<Vec<T>>,

Source§

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

Tests for self and other values to be equal, and is used by ==.
Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<VecChain<T>> for Vec<T>
where Vec<T>: PartialEq<Vec<T>>,

Source§

fn eq(&self, other: &VecChain<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &VecChain<T>) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq for VecChain<T>
where Vec<T>: PartialEq<Vec<T>>,

Source§

fn eq(&self, other: &VecChain<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &VecChain<T>) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

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

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

fn lt(&self, other: &Vec<T>) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &Vec<T>) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn gt(&self, other: &Vec<T>) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn ge(&self, other: &Vec<T>) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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

Source§

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

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

fn lt(&self, other: &VecChain<T>) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &VecChain<T>) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn gt(&self, other: &VecChain<T>) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn ge(&self, other: &VecChain<T>) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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

Source§

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

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

fn lt(&self, other: &VecChain<T>) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &VecChain<T>) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn gt(&self, other: &VecChain<T>) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn ge(&self, other: &VecChain<T>) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Copy for VecChain<T>
where Vec<T>: Copy,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> Encode for T

Source§

fn encode<E>(self) -> <E as Encoding>::EncodeOutput
where T: Encodable<E>, E: Encoding,

Source§

fn decode<E>(self) -> <E as Encoding>::DecodeOutput
where T: Decodable<E>, E: Encoding,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.