Struct worker::RouteContext

source ·
pub struct RouteContext<D> {
    pub data: D,
    pub env: Env,
    /* private fields */
}
Expand description

Container for a route’s parsed parameters, data, and environment bindings from the Runtime (such as KV Stores, Durable Objects, Variables, and Secrets).

Fields§

§data: D§env: Env

Implementations§

source§

impl<D> RouteContext<D>

source

pub fn data(&self) -> &D

👎Deprecated since 0.0.8: please use the data field directly

Get a reference to the generic associated data provided to the Router.

source

pub fn get_env(self) -> Env

👎Deprecated since 0.0.8: please use the env field directly

Get the Env for this Worker. Typically users should opt for the secret, var, kv and durable_object methods on the RouteContext instead.

source

pub fn secret(&self, binding: &str) -> Result<Secret>

Get a Secret value associated with this Worker, should one exist.

source

pub fn var(&self, binding: &str) -> Result<Var>

Get an Environment Variable value associated with this Worker, should one exist.

source

pub fn kv(&self, binding: &str) -> Result<KvStore>

Get a KV Namespace associated with this Worker, should one exist.

source

pub fn durable_object(&self, binding: &str) -> Result<ObjectNamespace>

Get a Durable Object Namespace associated with this Worker, should one exist.

source

pub fn param(&self, key: &str) -> Option<&String>

Get a URL parameter parsed by the router, by the name of its match or wildecard placeholder.

source

pub fn service(&self, binding: &str) -> Result<Fetcher>

Get a Service Binding for Worker-to-Worker communication.

source

pub fn bucket(&self, binding: &str) -> Result<Bucket>

Get a R2 Bucket associated with this Worker, should one exist.

Auto Trait Implementations§

§

impl<D> RefUnwindSafe for RouteContext<D>where D: RefUnwindSafe,

§

impl<D> !Send for RouteContext<D>

§

impl<D> !Sync for RouteContext<D>

§

impl<D> Unpin for RouteContext<D>where D: Unpin,

§

impl<D> UnwindSafe for RouteContext<D>where D: UnwindSafe,

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.