Struct runestick::BorrowRef[][src]

pub struct BorrowRef<'a, T: ?Sized + 'a> { /* fields omitted */ }
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

Map the reference.

Examples

use runestick::{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][..]);

Try to map the reference to a projection.

Examples

use runestick::{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

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.