RegionBuffer

Struct RegionBuffer 

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

A contiguous growable array type, allow you to obtain multiple mutable regions from it, as long these regions don’t overlap.

Implementations§

Source§

impl<T> RegionBuffer<T>

Source

pub fn new() -> Self

Constructs a new, empty RegionBuffer<T>. The buffer will not allocate until elements are pushed onto it.

Source

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

Appends an element to the back of a collection.

§Panics

Panics if the number of elements in the buffer overflows a usize.

Source

pub fn len(&self) -> usize

Returns the number of elements in the buffer, also referred to as its ‘length’.

Source

pub fn is_empty(&self) -> bool

Returns true if the region buffer contains no elements.

Source

pub fn truncate(&self, len: usize)

Shortens the buffer, keeping the first len elements and dropping the rest. If len is greater than the buffer’s current length, this has no effect.

Note that this method has no effect on the allocated capacity of the buffer.

§Panics

If len is less than an already borrowed region.

Source

pub fn region(&self, start: usize, end: usize) -> Slice<'_, T>

Provides a mutable reference to a region in the buffer, provided that region hasn’t already been borrowed.

§Panics

If the region has already been borrowed.

Source

pub fn get(&self, index: usize) -> Element<'_, T>

Returns a single element from the buffer. The borrowing rules also apply to this single element, so you can’t get a single element from an already borrowed region and vice versa.

Source

pub fn get_mut(&self, index: usize) -> ElementMut<'_, T>

Returns a single mutable element from the buffer. The borrowing rules also apply to this single element, so you can’t get a single element from an already borrowed region and vice versa.

Source§

impl<T: Clone> RegionBuffer<T>

Source

pub fn from_elements(element: T, len: usize) -> Self

Initialise a buffer of len size, with all elements initialised to element.

Source

pub fn expand(&mut self, to: usize, element: T)

Expands the region by to size, with all new elements initialised to element.

Trait Implementations§

Source§

impl<T: Debug> Debug for RegionBuffer<T>

Source§

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

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

impl<T: Default> Default for RegionBuffer<T>

Source§

fn default() -> RegionBuffer<T>

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

impl<T> Sync for RegionBuffer<T>

Auto Trait Implementations§

§

impl<T> !Freeze for RegionBuffer<T>

§

impl<T> !RefUnwindSafe for RegionBuffer<T>

§

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

§

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

§

impl<T> UnwindSafe for RegionBuffer<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> 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, 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.