Skip to main content

FromContext

Trait FromContext 

Source
pub trait FromContext: Sized + FromContextBounds {
    // Required method
    fn from_context(ctx: &Context) -> impl ContextFutureBounds<Output = Self>;
}
Expand description

Trait for extracting typed data from bot context

Similar to skyzen’s Extractor trait, this allows handlers to declare what data they need as function parameters.

§Example

// Built-in extractors
async fn greet(user: User) -> String {
    format!("Hello, {}!", user.name)
}

async fn echo(args: CommandArgs) -> String {
    args.0
}

Required Methods§

Source

fn from_context(ctx: &Context) -> impl ContextFutureBounds<Output = Self>

Extract data from the context

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromContext for ()

Source§

async fn from_context(_ctx: &Context) -> Self

Source§

impl<T1: FromContext> FromContext for (T1,)

Source§

async fn from_context(ctx: &Context) -> Self

Source§

impl<T1: FromContext, T2: FromContext> FromContext for (T1, T2)

Source§

async fn from_context(ctx: &Context) -> Self

Source§

impl<T1: FromContext, T2: FromContext, T3: FromContext> FromContext for (T1, T2, T3)

Source§

async fn from_context(ctx: &Context) -> Self

Source§

impl<T1: FromContext, T2: FromContext, T3: FromContext, T4: FromContext> FromContext for (T1, T2, T3, T4)

Source§

async fn from_context(ctx: &Context) -> Self

Implementors§