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<U: ?Sized>(this: Self, m: impl FnOnce(&T) -> &U) -> BorrowRef<'a, U>
pub fn map<U: ?Sized>(this: Self, m: impl FnOnce(&T) -> &U) -> BorrowRef<'a, U>
Map the reference.
§Examples
use rune::runtime::{BorrowRef, Bytes};
use rune::alloc::try_vec;
let bytes = rune::to_value(Bytes::from_vec(try_vec![1, 2, 3, 4]))?;
let bytes = bytes.borrow_ref::<Bytes>()?;
let bytes: BorrowRef<[u8]> = BorrowRef::map(bytes, |bytes| &bytes[0..2]);
assert_eq!(&bytes[..], &[1u8, 2u8][..]);
Sourcepub fn try_map<U: ?Sized>(
this: Self,
m: impl FnOnce(&T) -> Option<&U>,
) -> Result<BorrowRef<'a, U>, Self>
pub fn try_map<U: ?Sized>( this: Self, m: impl FnOnce(&T) -> Option<&U>, ) -> Result<BorrowRef<'a, U>, Self>
Try to map the reference to a projection.
§Examples
use rune::runtime::{BorrowRef, Bytes};
use rune::alloc::try_vec;
let bytes = rune::to_value(Bytes::from_vec(try_vec![1, 2, 3, 4]))?;
let bytes = bytes.borrow_ref::<Bytes>()?;
let Ok(bytes) = BorrowRef::try_map(bytes, |bytes| bytes.get(0..2)) else {
panic!("Conversion failed");
};
assert_eq!(&bytes[..], &[1u8, 2u8][..]);
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
Source§impl<T> EncodedChars for T
impl<T> EncodedChars for T
Source§fn encoding(&self) -> *mut OnigEncodingTypeST
fn encoding(&self) -> *mut OnigEncodingTypeST
The encoding of the contents of the buffer