pub struct DispatchData<'a> {
    data: &'a mut dyn Any,
}
Expand description

Holder of global dispatch-related data

This struct serves as a dynamic container for the dispatch-time global data that you gave to the dispatch method, and is given as input to all your callbacks. It allows you to share global state between your filters.

The main method of interest is the get method, which allows you to access a &mut _ reference to the global data itself. The other methods are mostly used internally by the crate.

Fields§

§data: &'a mut dyn Any

Implementations§

source§

impl<'a> DispatchData<'a>

source

pub fn get<T: Any>(&mut self) -> Option<&mut T>

Access the dispatch data knowing its type

Will return None if the provided type is not the correct inner type.

source

pub fn wrap<T: Any>(data: &'a mut T) -> DispatchData<'a>

Wrap a mutable reference

This creates a new DispatchData from a mutable reference

source

pub fn reborrow(&mut self) -> DispatchData<'_>

Reborrows this DispatchData to create a new one with the same content

This is a quick and cheap way to propagate the DispatchData down a callback stack by value. It is basically a noop only there to ease work with the borrow checker.

Trait Implementations§

source§

impl<'a> Debug for DispatchData<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'a> Unpin for DispatchData<'a>

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.