[−][src]Struct runestick::AnyObj
Our own private dynamic Any implementation.
In contrast to Box<dyn std::any::Any>
, this allows for storing a raw
pointer directly in the object to avoid one level of indirection. Otherwise
it's equivalent.
Implementations
impl AnyObj
[src]
pub fn new<T>(data: T) -> Self where
T: Any,
[src]
T: Any,
Construct a new any from the original any.
pub fn from_ref<T>(data: &T) -> Self where
T: Any,
[src]
T: Any,
Construct an Any that wraps a pointer.
pub fn from_mut<T>(data: &mut T) -> Self where
T: Any,
[src]
T: Any,
Construct an Any that wraps a mutable pointer.
pub unsafe fn new_raw(vtable: &'static AnyObjVtable, data: *const ()) -> Self
[src]
Construct a new any with the specified raw components.
Safety
The caller must ensure that the vtable matches up with the data pointer provided. This is primarily public for use in a C ffi.
pub fn is<T>(&self) -> bool where
T: Any,
[src]
T: Any,
Returns true
if the boxed type is the same as T
.
Examples
use runestick::Any; #[derive(Debug, Any)] struct Foo; #[derive(Debug, Any)] struct Other; let any = runestick::AnyObj::new(Foo); assert!(any.is::<Foo>()); assert!(!any.is::<Other>());
pub fn downcast_borrow_ref<T>(&self) -> Option<&T> where
T: Any,
[src]
T: Any,
Returns some reference to the boxed value if it is of type T
, or
None
if it isn't.
Examples
use runestick::Any; #[derive(Debug, PartialEq, Eq, Any)] struct Thing(u32); #[derive(Debug, PartialEq, Eq, Any)] struct Other; let any = runestick::AnyObj::new(Thing(1u32)); assert_eq!(Some(&Thing(1u32)), any.downcast_borrow_ref::<Thing>()); assert_eq!(None, any.downcast_borrow_ref::<Other>());
pub fn downcast_borrow_mut<T>(&mut self) -> Option<&mut T> where
T: Any,
[src]
T: Any,
Returns some mutable reference to the boxed value if it is of type T
, or
None
if it isn't.
Examples
use runestick::Any; #[derive(Debug, PartialEq, Eq, Any)] struct Thing(u32); let mut any = runestick::AnyObj::new(Thing(1u32)); any.downcast_borrow_mut::<Thing>().unwrap().0 = 2; assert_eq!(Some(&Thing(2u32)), any.downcast_borrow_ref::<Thing>());
pub fn raw_as_ptr(&self, expected: Hash) -> Option<*const ()>
[src]
Attempt to perform a conversion to a raw pointer.
pub fn raw_as_mut(&mut self, expected: Hash) -> Option<*mut ()>
[src]
Attempt to perform a conversion to a raw mutable pointer.
pub fn raw_take(self, expected: Hash) -> Result<*mut (), Self>
[src]
Attempt to perform a conversion to a raw mutable pointer with the intent of taking it.
If the conversion is not possible, we return a reconstructed Any
as
the error variant.
pub fn debug(&self, f: &mut Formatter<'_>) -> Result
[src]
Debug format the current any type.
pub fn type_name(&self) -> RawStr
[src]
Access the underlying type name for the data.
pub fn type_hash(&self) -> Hash
[src]
Access the underlying type id for the data.
Trait Implementations
impl Debug for AnyObj
[src]
impl Drop for AnyObj
[src]
impl From<AnyObj> for Value
[src]
impl ToValue for AnyObj
[src]
Auto Trait Implementations
impl RefUnwindSafe for AnyObj
impl !Send for AnyObj
impl !Sync for AnyObj
impl Unpin for AnyObj
impl UnwindSafe for AnyObj
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,