Struct fyrox_core::pool::MultiBorrowContext
source · 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,
impl<'a, const N: usize, T, P> MultiBorrowContext<'a, N, T, P>where
T: Sized,
P: PayloadContainer<Element = T> + 'static,
sourcepub fn try_get(&mut self, handle: Handle<T>) -> Option<&'a mut T>
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:
- A reference to an element is already taken - returning multiple mutable references to the same element is forbidden by Rust safety rules.
- 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
. - 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> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
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
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.