pub struct BorrowRef<'a, T: ?Sized + 'a> { /* private fields */ }
Expand description
Guard for a data borrowed from a slot in the virtual machine.
These guards are necessary, since we need to guarantee certain forms of access depending on what we do. Releasing the guard releases the access.
Implementations§
source§impl<'a, T: ?Sized> BorrowRef<'a, T>
impl<'a, T: ?Sized> BorrowRef<'a, T>
sourcepub fn map<M, U: ?Sized>(this: Self, m: M) -> BorrowRef<'a, U>
pub fn map<M, U: ?Sized>(this: Self, m: M) -> BorrowRef<'a, U>
Map the reference.
§Examples
use rune::runtime::{BorrowRef, Shared};
let vec = Shared::<Vec<u32>>::new(vec![1, 2, 3, 4])?;
let vec = vec.borrow_ref()?;
let value: BorrowRef<[u32]> = BorrowRef::map(vec, |vec| &vec[0..2]);
assert_eq!(&*value, &[1u32, 2u32][..]);
sourcepub fn try_map<M, U: ?Sized>(this: Self, m: M) -> Option<BorrowRef<'a, U>>
pub fn try_map<M, U: ?Sized>(this: Self, m: M) -> Option<BorrowRef<'a, U>>
Try to map the reference to a projection.
§Examples
use rune::runtime::{BorrowRef, Shared};
let vec = Shared::<Vec<u32>>::new(vec![1, 2, 3, 4])?;
let vec = vec.borrow_ref()?;
let mut value: Option<BorrowRef<[u32]>> = BorrowRef::try_map(vec, |vec| vec.get(0..2));
assert_eq!(value.as_deref(), Some(&[1u32, 2u32][..]));
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for BorrowRef<'a, T>where
T: ?Sized,
impl<'a, T> !RefUnwindSafe for BorrowRef<'a, T>
impl<'a, T> !Send for BorrowRef<'a, T>
impl<'a, T> !Sync for BorrowRef<'a, T>
impl<'a, T> Unpin for BorrowRef<'a, T>where
T: ?Sized,
impl<'a, T> !UnwindSafe for BorrowRef<'a, T>
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
Mutably borrows from an owned value. Read more