Trait do_proxy::EnvExt

source ·
pub trait EnvExt {
    fn obj<Obj>(&self, name: &str) -> Result<Proxy<Obj>, Error>
    where
        Obj: DoProxy
; fn obj_from_id<Obj>(&self, id: &str) -> Result<Proxy<Obj>, Error>
    where
        Obj: DoProxy
; fn unique_obj<Obj>(&self) -> Result<Proxy<Obj>, Error>
    where
        Obj: DoProxy
; }
Expand description

The EnvExt trait makes it easy to create proxies from a worker::Env.

Defines multiple methods on the [workers::Env] type to make it easier to create proxies.

Example

#[worker::event(fetch, respond_with_errors)]
pub async fn main(mut req: Request, env: Env, _ctx: worker::Context) -> Result<Response> {
    let url = req.url()?;
    let do_name = url.path();

    let command = req.json().await?;
     
    // Easily access an `Inserter` object with the given name.
    let inserter = env.obj::<Inserter>(do_name)?;
    let resp = inserter.send(command).await??;

    Response::from_json(&resp)
}

Required Methods

Get a proxy to a durable object with the given name.

env.obj::<Inserter>("inserter_for_fisher")?;

Get a proxy to a durable object with the given hex ID.

env.obj::<Inserter>("<long_hex_string>")?;

Get a unique proxy to a durable object.

Implementations on Foreign Types

Implementors