Skip to main content

Fragment

Struct Fragment 

Source
pub struct Fragment<T> { /* private fields */ }
Expand description

A contiguous fragment of the split vector.

Suppose a split vector contains 10 integers from 0 to 9. Depending on the growth strategy of the split vector, this data might be stored in 3 contiguous fragments, say [0, 1, 2, 3], [4, 5, 6, 7] and [8, 9].

Implementations§

Source§

impl<T> Fragment<T>

Source

pub fn new(capacity: usize, data: Vec<T>) -> Self

Creates a fragment from data with the target logical capacity.

Source

pub fn new_empty(capacity: usize) -> Self

Creates a new fragment with the given capacity.

Source

pub fn into_inner(self) -> Vec<T>

Consumes the fragment and returns the inner vector.

Source

pub fn has_capacity_for_one(&self) -> bool

Returns whether the fragment has room to push a new item or not.

Source

pub fn room(&self) -> usize

Returns the available capacity in the fragment.

Source

pub fn len(&self) -> usize

Returns the number of initialized elements in the fragment.

Source

pub fn is_empty(&self) -> bool

Returns true if the fragment contains no elements.

Source

pub fn capacity(&self) -> usize

Returns the logical capacity of the fragment.

Source

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

Returns a shared slice view of initialized elements.

Source

pub fn as_ptr(&self) -> *const T

Returns a raw pointer to the fragment’s initialized elements.

Source

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

Binary-searches initialized elements with a comparator.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over initialized elements.

Source

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

Returns the last initialized element, if any.

Source

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

Returns the first initialized element, if any.

Source

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

Returns a shared reference to the element at index, if present.

Source

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

Returns a shared reference to the element at index without bounds checks.

§Safety

Caller must ensure index < self.len().

Source

pub fn push(&mut self, value: T)

Appends an element to the end of initialized region.

Source

pub unsafe fn set_len(&mut self, new_len: usize)

Sets the initialized length of the fragment.

§Safety

Caller must uphold Vec::set_len invariants.

Source

pub unsafe fn as_mut_vec(&mut self) -> &mut Vec<T>

§SAFETY

Obtained reference to the vector can be used to change the length of the vector by adding or removing elements; however, it must not change the capacity and underlying allocation of the vector.

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Returns a mutable raw pointer to initialized elements.

Source

pub fn extend_from_slice(&mut self, slice: &[T])
where T: Clone,

Clones and appends all elements from slice.

Source

pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T

Returns a mutable reference to the element at index without bounds checks.

§Safety

Caller must ensure index < self.len() and aliasing rules are respected.

Source

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

Removes and returns the last element, if any.

Source

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

Inserts element at index, shifting later elements to the right.

Source

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

Removes and returns the element at index, shifting later elements left.

Source

pub fn clear(&mut self)

Removes all initialized elements from the fragment.

Source

pub fn truncate(&mut self, len: usize)

Truncates the initialized length to at most len.

Source

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

Swaps two initialized elements.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over initialized elements.

Source

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

Sorts initialized elements with the given comparator.

Trait Implementations§

Source§

impl<T: Clone> Clone for Fragment<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Fragment<T>
where T: Debug,

Source§

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

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

impl<T: Default> Default for Fragment<T>

Source§

fn default() -> Fragment<T>

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

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

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

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

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Index<RangeFull> for Fragment<T>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

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

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

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

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

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

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Index<usize> for Fragment<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

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

Source§

fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

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

Source§

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<RangeFull> for Fragment<T>

Source§

fn index_mut(&mut self, index: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

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

Source§

fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

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

Source§

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

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

Source§

fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for Fragment<T>

Source§

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

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IntoIterator for Fragment<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq> PartialEq<Fragment<T>> for [T]

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PartialEq> PartialEq<Fragment<T>> for Vec<T>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PartialEq, const N: usize> PartialEq<Fragment<T>> for [T; N]

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PartialEq, U> PartialEq<U> for Fragment<T>
where U: AsRef<[T]>,

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Fragment<T>

§

impl<T> RefUnwindSafe for Fragment<T>
where T: RefUnwindSafe,

§

impl<T> Send for Fragment<T>
where T: Send,

§

impl<T> Sync for Fragment<T>
where T: Sync,

§

impl<T> Unpin for Fragment<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Fragment<T>

§

impl<T> UnwindSafe for Fragment<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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> SoM<T> for T

Source§

fn get_ref(&self) -> &T

Returns a reference to self.
Source§

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

Returns a mutable reference to self.
Source§

impl<T> SoR<T> for T

Source§

fn get_ref(&self) -> &T

Returns a reference to self.
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.