pub struct MultiBorrowContext<'a, const N: usize, T, P = Option<T>>where
    T: Sized,
    P: PayloadContainer<Element = T> + 'static,{ /* private fields */ }
Expand description

Multi-borrow context allows you to get as many unique references to elements in a pool as you want.

Implementations§

source§

impl<'a, const N: usize, T, P> MultiBorrowContext<'a, N, T, P>where T: Sized, P: PayloadContainer<Element = T> + 'static,

source

pub fn try_get(&mut self, handle: Handle<T>) -> Option<&'a mut T>

Tries to get a mutable reference to a pool element located at the given handle. The method could fail in three main reasons:

  1. A reference to an element is already taken - returning multiple mutable references to the same element is forbidden by Rust safety rules.
  2. You’re trying to get more references that the context could handle (there is not enough space in the internal handles storage) - in this case you must increase N.
  3. A given handle is invalid.
Performance

This method has O(N) complexity, internally it does linear search in the internal handles storage to enforce borrowing rules at runtime. The method is designed for small reference count (<32), where linear search is faster than hash set.

Auto Trait Implementations§

§

impl<'a, const N: usize, T, P> RefUnwindSafe for MultiBorrowContext<'a, N, T, P>where P: RefUnwindSafe, T: RefUnwindSafe,

§

impl<'a, const N: usize, T, P> Send for MultiBorrowContext<'a, N, T, P>where P: Send,

§

impl<'a, const N: usize, T, P> Sync for MultiBorrowContext<'a, N, T, P>where P: Sync,

§

impl<'a, const N: usize, T, P> Unpin for MultiBorrowContext<'a, N, T, P>where T: Unpin,

§

impl<'a, const N: usize, T, P = Option<T>> !UnwindSafe for MultiBorrowContext<'a, N, T, P>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> FieldValue for Twhere T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V