Struct Argument

Source
pub struct Argument<'a> { /* private fields */ }
Expand description

A variant item that implements Copy-on-Write.

It acts similarly to a Cow, except for two things:

  1. It is encapsulated, meaning that the inner contents cannot be accessed.
  2. The storage is handled differently compared to Cow, which allows for a smaller type size.

Implementations§

Source§

impl Argument<'_>

Source

pub fn new_owned<T>(item: T) -> Self
where T: Any + Clone,

Creates a new owned Argument.

Source

pub fn is_owned(&self) -> bool

Checks if the argument is owned.

Source

pub fn is_borrowed(&self) -> bool

Checks if the argument is borrowed.

Source

pub fn to_mut(&mut self) -> &mut dyn Any

Returns a mutable reference to the item itself.

If the inner contents are borrowed, this creates a new owned instance first before returning the reference itself.

Source

pub fn to_owned(&self) -> Self

Clones the inner contents of the object, returning an owned argument.

Source

pub fn downcast_owned<T>(self) -> Result<T, Self>
where T: Clone + Any,

Downcasts an owned argument into type T, returning a result.

§Return values

Ok(T): The argument gets consumed and returns the inner contents. Err(Self): Either the argument is not of type T or the argument itself is not owned.

Source

pub unsafe fn downcast_owned_unchecked<T>(self) -> T
where T: Clone + Any,

Downcasts an owned argument into type T, without any checks.

§Safety

The argument must both be owned and of type T.

§Panics

The function will panic if the argument itself is not owned.

Source

pub fn downcast_cloned<T>(&self) -> Option<T>
where T: Any + Clone,

Downcasts the argument into a cloned object of type T.

Returns None if the object’s type is not T.

Source

pub unsafe fn downcast_cloned_unchecked<T>(&self) -> T
where T: Any + Clone,

Downcasts the argument into a cloned object of T without checking it first.

§Safety

Assumes that the contents are of type T.

Source§

impl<'a> Argument<'a>

Source

pub fn new_borrowed<T>(item: &'a T) -> Self
where T: Any + Clone,

Creates a borrowed argument of item T.

Source

pub fn as_ref(&'a self) -> Self

Creates a borrowed reference to the source argument.

Source

pub fn into_inner(self) -> ArgumentKind<'a>

Consumes the argument itself, returning what kind of argument it is.

Trait Implementations§

Source§

impl<'a> Clone for Argument<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Argument<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Argument<'_>

Source§

type Target = dyn Any

The resulting type after dereferencing.
Source§

fn deref(&self) -> &dyn Any

Dereferences the value.
Source§

impl Drop for Argument<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Argument<'a>

§

impl<'a> !RefUnwindSafe for Argument<'a>

§

impl<'a> !Send for Argument<'a>

§

impl<'a> !Sync for Argument<'a>

§

impl<'a> Unpin for Argument<'a>

§

impl<'a> !UnwindSafe for Argument<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.