Skip to main content

Router

Struct Router 

Source
pub struct Router { /* private fields */ }
Expand description

Handler registry + filter pipeline with middleware and nesting.

Implementations§

Source§

impl Router

Source

pub fn new() -> Self

Create an empty router.

Source

pub fn named(name: &'static str) -> Self

Create an empty router with a diagnostic name.

Source

pub fn name(&self) -> &'static str

The router’s diagnostic name (empty if unnamed).

Source

pub fn use_middleware<F>(&mut self, middleware: F)
where F: for<'a> Fn(&Event, &ExtractBag, Next<'a>) -> HandlerResult + Send + Sync + 'static,

Attach a middleware to this router.

The middleware wraps every route registered on this router and on any router later nested via Router::include. Middleware added on a parent runs outside middleware added on a child; the innermost middleware wraps the handler itself.

Source

pub fn include(&mut self, child: Router)

Nest a child router. The child keeps its own filters and middleware; this router’s middleware wraps around them.

Source

pub fn on_message<F>(&mut self, handler: F)
where F: Fn(&Message) -> HandlerResult + Send + Sync + 'static,

Register a handler for every MESSAGE_CREATE event.

Source

pub fn on_message_filtered<F>( &mut self, handler: F, filters: Vec<MessageFilter>, )
where F: Fn(&Message) -> HandlerResult + Send + Sync + 'static,

Register a MESSAGE_CREATE handler guarded by filters (AND’d).

Source

pub fn add_message_handler(&mut self, definition: MessageHandlerDef)

Register a handler definition produced by #[vaidcord::on_message].

Source

pub fn on_event<F>(&mut self, kind: EventKind, handler: F)
where F: Fn(&Event) -> HandlerResult + Send + Sync + 'static,

Register a handler for an arbitrary event kind.

Source

pub fn on_ready<F>(&mut self, handler: F)
where F: Fn(&Ready) -> HandlerResult + Send + Sync + 'static,

Register a handler for the gateway READY event.

Source

pub fn on_interaction<F>(&mut self, handler: F)
where F: Fn(&Interaction) -> HandlerResult + Send + Sync + 'static,

Register a handler for INTERACTION_CREATE events.

Source

pub fn dispatch_message(&self, message: &Message) -> HandlerResult

Dispatch a message through this router tree (filters + middleware).

Convenience wrapper that builds a one-shot Dispatcher; for the hot path build a Dispatcher once and reuse it so middleware chains stay precomposed.

Trait Implementations§

Source§

impl Default for Router

Source§

fn default() -> Router

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more