pub struct Ref<T: ?Sized> { /* private fields */ }
Expand description
A strong owned reference to the given type that can be safely dereferenced.
§Examples
Constructed from a static value:
use rune::Ref;
let value: Ref<str> = Ref::from_static("hello world");
Implementations§
Source§impl<T: ?Sized> Ref<T>
impl<T: ?Sized> Ref<T>
Sourcepub const fn from_static(value: &'static T) -> Ref<T>
pub const fn from_static(value: &'static T) -> Ref<T>
Construct an owned reference from a static value.
§Examples
use rune::Ref;
let value: Ref<str> = Ref::from_static("Hello World");
assert_eq!(value.as_ref(), "Hello World");
Sourcepub fn map<U: ?Sized, F>(this: Self, f: F) -> Ref<U>
pub fn map<U: ?Sized, F>(this: Self, f: F) -> Ref<U>
Map the interior reference of an owned mutable value.
§Examples
use rune::Ref;
use rune::runtime::Bytes;
use rune::alloc::try_vec;
let bytes = rune::to_value(Bytes::from_vec(try_vec![1, 2, 3, 4]))?;
let bytes: Ref<Bytes> = rune::from_value(bytes)?;
let value: Ref<[u8]> = Ref::map(bytes, |vec| &vec[0..2]);
assert_eq!(&*value, &[1, 2][..]);
Sourcepub fn try_map<U: ?Sized, F>(this: Self, f: F) -> Result<Ref<U>, Ref<T>>
pub fn try_map<U: ?Sized, F>(this: Self, f: F) -> Result<Ref<U>, Ref<T>>
Try to map the reference to a projection.
§Examples
use rune::Ref;
use rune::runtime::Bytes;
use rune::alloc::try_vec;
let bytes = rune::to_value(Bytes::from_vec(try_vec![1, 2, 3, 4]))?;
let bytes: Ref<Bytes> = rune::from_value(bytes)?;
let Ok(value) = Ref::try_map(bytes, |bytes| bytes.get(0..2)) else {
panic!("Conversion failed");
};
assert_eq!(&value[..], &[1, 2][..]);
Sourcepub fn into_raw(this: Self) -> (NonNull<T>, RawAnyGuard)
pub fn into_raw(this: Self) -> (NonNull<T>, RawAnyGuard)
Convert into a raw pointer and associated raw access guard.
§Safety
The returned pointer must not outlive the associated guard, since this prevents other uses of the underlying data which is incompatible with the current.
Sourcepub unsafe fn from_raw(value: NonNull<T>, guard: RawAnyGuard) -> Self
pub unsafe fn from_raw(value: NonNull<T>, guard: RawAnyGuard) -> Self
Convert a raw reference and guard into a regular reference.
§Safety
The caller is responsible for ensuring that the raw reference is associated with the specific pointer.
Trait Implementations§
Source§impl<T> FromValue for Ref<T>where
T: AnyMarker,
impl<T> FromValue for Ref<T>where
T: AnyMarker,
Source§fn from_value(value: Value) -> Result<Self, RuntimeError>
fn from_value(value: Value) -> Result<Self, RuntimeError>
Try to convert to the given type, from the given value.
Source§impl FromValue for Ref<Tuple>
impl FromValue for Ref<Tuple>
Source§fn from_value(value: Value) -> Result<Self, RuntimeError>
fn from_value(value: Value) -> Result<Self, RuntimeError>
Try to convert to the given type, from the given value.
Source§impl FromValue for Ref<str>
impl FromValue for Ref<str>
Source§fn from_value(value: Value) -> Result<Self, RuntimeError>
fn from_value(value: Value) -> Result<Self, RuntimeError>
Try to convert to the given type, from the given value.
Source§impl<T> MaybeTypeOf for Ref<T>where
T: ?Sized + MaybeTypeOf,
impl<T> MaybeTypeOf for Ref<T>where
T: ?Sized + MaybeTypeOf,
Source§fn maybe_type_of() -> Result<DocType>
fn maybe_type_of() -> Result<DocType>
Type information for the given type.
Source§impl<T> TypeOf for Ref<T>
Blanket implementation for owned references.
impl<T> TypeOf for Ref<T>
Blanket implementation for owned references.
Source§const PARAMETERS: Hash = T::PARAMETERS
const PARAMETERS: Hash = T::PARAMETERS
Type parameters for the type. Read more
Source§const STATIC_TYPE_INFO: AnyTypeInfo = T::STATIC_TYPE_INFO
const STATIC_TYPE_INFO: AnyTypeInfo = T::STATIC_TYPE_INFO
Access diagnostical type information for the current type. Read more
Auto Trait Implementations§
impl<T> Freeze for Ref<T>where
T: ?Sized,
impl<T> RefUnwindSafe for Ref<T>where
T: RefUnwindSafe + ?Sized,
impl<T> !Send for Ref<T>
impl<T> !Sync for Ref<T>
impl<T> Unpin for Ref<T>where
T: ?Sized,
impl<T> UnwindSafe for Ref<T>where
T: RefUnwindSafe + ?Sized,
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