pub struct AnyObj { /* private fields */ }Expand description
A type-erased wrapper for a reference.
Implementations§
Source§impl AnyObj
impl AnyObj
Sourcepub fn new<T>(data: T) -> Result<Self>where
T: Any,
pub fn new<T>(data: T) -> Result<Self>where
T: Any,
Construct an Any that wraps an owned object.
§Examples
use rune::Value;
use rune::runtime::AnyObj;
use rune::alloc::String;
let string = String::try_from("Hello World")?;
let string = AnyObj::new(string)?;
let string = Value::from(string);
let string = string.into_shared::<String>()?;
assert_eq!(string.borrow_ref()?.as_str(), "Hello World");Sourcepub fn take(self) -> Result<Self, AnyObjError>
pub fn take(self) -> Result<Self, AnyObjError>
Take the interior value and return a handle to the taken value.
Sourcepub fn borrow_ref<T>(&self) -> Result<BorrowRef<'_, T>, AnyObjError>where
T: Any,
pub fn borrow_ref<T>(&self) -> Result<BorrowRef<'_, T>, AnyObjError>where
T: Any,
Get a reference to the interior value while checking for shared access.
This prevents other exclusive accesses from being performed while the guard returned from this function is live.
Sourcepub fn try_borrow_ref<T>(&self) -> Result<Option<BorrowRef<'_, T>>, AccessError>where
T: Any,
pub fn try_borrow_ref<T>(&self) -> Result<Option<BorrowRef<'_, T>>, AccessError>where
T: Any,
Try to borrow a reference to the interior value while checking for shared access.
Returns None if the interior type is not T.
This prevents other exclusive accesses from being performed while the guard returned from this function is alive.
Sourcepub fn try_borrow_mut<T>(&self) -> Result<Option<BorrowMut<'_, T>>, AccessError>where
T: Any,
pub fn try_borrow_mut<T>(&self) -> Result<Option<BorrowMut<'_, T>>, AccessError>where
T: Any,
Try to borrow a reference to the interior value while checking for exclusive access.
Returns None if the interior type is not T.
This prevents other exclusive accesses from being performed while the guard returned from this function is alive.
Sourcepub fn borrow_mut<T>(&self) -> Result<BorrowMut<'_, T>, AnyObjError>where
T: Any,
pub fn borrow_mut<T>(&self) -> Result<BorrowMut<'_, T>, AnyObjError>where
T: Any,
Returns some mutable reference to the boxed value if it is of type T.
Trait Implementations§
Source§impl From<AnyObj> for Value
impl From<AnyObj> for Value
§Examples
use rune::Value;
use rune::runtime::AnyObj;
use rune::alloc::String;
let string = String::try_from("Hello World")?;
let string = AnyObj::new(string)?;
let string = Value::from(string);
let string = string.into_shared::<String>()?;
assert_eq!(string.borrow_ref()?.as_str(), "Hello World");