pub struct OwnedArgument { /* private fields */ }Expand description
An owned argument.
This carries a generic item that implements both Any and Clone. In addition, depending on the storage itself, it is able to implement items whose size is no more than 8 bytes for 64-bit systems (or 4 for 32-bit systems).
Implementations§
Source§impl OwnedArgument
impl OwnedArgument
Sourcepub fn new<T>(item: T) -> Self
pub fn new<T>(item: T) -> Self
Creates a new OwnedArgument based around a generic item.
If the size of said item is less than 8 bytes for 64-bit systems (4 for 32-bit systems), then the storage is inlined. Otherwise, the storage gets allocated instead.
Sourcepub fn is_type<T>(&self) -> bool
pub fn is_type<T>(&self) -> bool
A “wrapper” for Any::is::<T>().
In case Any interferes with dereferencing the OwnedArgument, use the following function instead.
Sourcepub fn downcast_owned<T>(self) -> Result<T, Self>
pub fn downcast_owned<T>(self) -> Result<T, Self>
Downcasts the object into an owned instance.
§Return values:
Ok(val): The value matches is T, and the previous storage frees itself. Err(self): The value does not match T, the inner value should remain identical.
Sourcepub unsafe fn downcast_owned_unchecked<T>(self) -> T
pub unsafe fn downcast_owned_unchecked<T>(self) -> T
Downcasts the inner value into T without checking it first.
§Safety
This assumes that the type supplied is, in fact, T.
Sourcepub fn downcast_cloned<T>(&self) -> Option<T>
pub fn downcast_cloned<T>(&self) -> Option<T>
Downcasts a reference of the OwnedArgument before returning the cloned contents of the inner value:
§Return values
Some(v): The cloned object is of type T, None: OwnedArgument is not type T
Sourcepub unsafe fn downcast_cloned_unchecked<T>(&self) -> T
pub unsafe fn downcast_cloned_unchecked<T>(&self) -> T
Returns the cloned contents of the inner type of an OwnedArgument without performing any checks.
§Safety
This assumes that the OwnedArgument is type T.