pub struct SimpleHolder<V>(/* private fields */);Expand description
A Holder that lends its inner value itself by cloning.
Implementations§
Source§impl<V: Clone> SimpleHolder<V>
impl<V: Clone> SimpleHolder<V>
pub fn new(value: V) -> Self
pub fn into_value(self) -> V
Methods from Deref<Target = Holder<V, V, V>>§
Sourcepub fn get_fn_imm(&self) -> fn(&V) -> BI
pub fn get_fn_imm(&self) -> fn(&V) -> BI
Returns immutable borrow function that you inserted at Holder::new.
Sourcepub fn get_fn_mut(&self) -> fn(&mut V) -> BM
pub fn get_fn_mut(&self) -> fn(&mut V) -> BM
Returns mutable borrow function that you inserted at Holder::new.
Sourcepub fn borrow(&self) -> BorrowResult<BI>
pub fn borrow(&self) -> BorrowResult<BI>
Borrows inner value.
If check feature is enabled, runtime borrow checker works and blocks
try borrowing value after mutable borrow.
§Examples
use my_ecs::ds::Holder;
let holder = unsafe { Holder::new(0, |v| v, |v| v) };
assert_eq!(*holder.borrow().unwrap(), &0);Sourcepub fn borrow_mut(&mut self) -> BorrowResult<BM>
pub fn borrow_mut(&mut self) -> BorrowResult<BM>
Borrows inner value mutably.
If check feature is enabled, runtime borrow checker works and blocks
try borrowing value after mutable or immutable borrow.
§Examples
use my_ecs::ds::Holder;
let mut holder = unsafe { Holder::new(0, |v| v, |v| v) };
**holder.borrow_mut().unwrap() = 1;
assert_eq!(*holder.borrow().unwrap(), &1);Sourcepub fn get(&self) -> BorrowResult<&V>
pub fn get(&self) -> BorrowResult<&V>
Returns shared reference to the inner value without calling immutable
borrow function that you inserted at Holder::new.
If check feature is enabled, runtime borrow checker works and blocks
try borrowing value after mutable borrow.
§Examples
use my_ecs::ds::Holder;
let holder = unsafe { Holder::new(0, |v| *v + 1, |v| *v + 1) };
let value = holder.get().unwrap();
assert_eq!(*value, &0); // Due to bypassed borrow function.Sourcepub fn get_mut(&mut self) -> BorrowResult<&mut V>
pub fn get_mut(&mut self) -> BorrowResult<&mut V>
Returns mutable reference to the inner value without calling mutable
borrow function that you inserted at Holder::new.
If check feature is enabled, runtime borrow checker works and blocks
try borrowing value after mutable or immutable borrow.
§Examples
use my_ecs::ds::Holder;
let mut holder = unsafe { Holder::new(0, |v| *v + 1, |v| *v + 1) };
let value = holder.get_mut().unwrap();
assert_eq!(*value, &mut 0); // Due to bypassed borrow function.Sourcepub unsafe fn get_unchecked(&self) -> &V
pub unsafe fn get_unchecked(&self) -> &V
Sourcepub unsafe fn get_unchecked_mut(&mut self) -> &mut V
pub unsafe fn get_unchecked_mut(&mut self) -> &mut V
Sourcepub fn borrow_count(&self) -> i32
pub fn borrow_count(&self) -> i32
Returns current reference count.
Returning reference count will be
- Greater than zero meaning there exist immutable borrow at the time.
- Lesser than zero meaning there exist mutable borrow at the time.
- Zero meaning no borrow at the time or
checkfeature is disabled.
Trait Implementations§
Source§impl<V: Debug> Debug for SimpleHolder<V>
impl<V: Debug> Debug for SimpleHolder<V>
Source§impl<V> Deref for SimpleHolder<V>
impl<V> Deref for SimpleHolder<V>
Auto Trait Implementations§
impl<V> Freeze for SimpleHolder<V>where
V: Freeze,
impl<V> RefUnwindSafe for SimpleHolder<V>where
V: RefUnwindSafe,
impl<V> Send for SimpleHolder<V>where
V: Send,
impl<V> Sync for SimpleHolder<V>where
V: Sync,
impl<V> Unpin for SimpleHolder<V>where
V: Unpin,
impl<V> UnwindSafe for SimpleHolder<V>where
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more