[][src]Struct stk::Any

#[repr(C)]pub struct Any { /* fields omitted */ }

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 Any[src]

pub fn new<T>(data: T) -> Self where
    T: Any
[src]

Construct a new any from the original any.

pub unsafe fn from_ptr<T>(data: *const T) -> Self where
    T: Any
[src]

Construct a new any from a pointer.

Safety

It is up to the caller to make sure that whatever data is pointed to is valid for the duration of the Any.

Examples

let value = 1u32;
let any = unsafe { stk::Any::from_ptr(&value) };
assert!(any.is::<u32>());
assert_eq!(Some(&1u32), any.downcast_ref());

pub unsafe fn from_mut_ptr<T>(data: *mut T) -> Self where
    T: Any
[src]

Construct a new any from a mutable pointer.

Safety

It is up to the caller to make sure that whatever data is pointed to is valid for the duration of the Any.

Examples

let mut value = 1u32;
let mut any = unsafe { stk::Any::from_mut_ptr(&mut value) };
assert!(any.is::<u32>());
*any.downcast_mut::<u32>().unwrap() = 2;
assert_eq!(Some(&2u32), any.downcast_ref());

pub fn is<T>(&self) -> bool where
    T: Any
[src]

Returns true if the boxed type is the same as T.

Examples

let any = stk::Any::new(1u32);
assert!(any.is::<u32>());

pub fn downcast_ref<T>(&self) -> Option<&T> where
    T: Any
[src]

Returns some reference to the boxed value if it is of type T, or None if it isn't.

Examples

let any = stk::Any::new(1u32);
assert_eq!(Some(&1u32), any.downcast_ref::<u32>());
assert_eq!(None, any.downcast_ref::<&u32>());

pub fn downcast_mut<T>(&mut self) -> Option<&mut T> where
    T: Any
[src]

Returns some mutable reference to the boxed value if it is of type T, or None if it isn't.

Examples

let mut any = stk::Any::new(1u32);
*any.downcast_mut::<u32>().unwrap() = 2;
assert_eq!(Some(&2u32), any.downcast_ref::<u32>());

pub fn as_ptr(&self, expected_type: TypeId) -> Option<*const ()>[src]

Attempt to perform a conversion to a raw pointer.

pub fn as_mut_ptr(&mut self, expected_type: TypeId) -> Option<*mut ()>[src]

Attempt to perform a conversion to a raw mutable pointer.

pub fn take_mut_ptr(self, expected_type: TypeId) -> 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 type_name(&self) -> &'static str[src]

Access the underlying type name for the data.

pub fn type_id(&self) -> TypeId[src]

Access the underlying type id for the data.

Trait Implementations

impl Debug for Any[src]

impl Drop for Any[src]

impl FromValue for Any[src]

Auto Trait Implementations

impl RefUnwindSafe for Any

impl !Send for Any

impl !Sync for Any

impl Unpin for Any

impl UnwindSafe for Any

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,