pub struct Fetcher(/* private fields */);
Expand description
A struct for invoking fetch events to other Workers.
Implementations§
source§impl Fetcher
impl Fetcher
sourcepub async fn fetch(
&self,
url: impl Into<String>,
init: Option<RequestInit>
) -> Result<HttpResponse>
pub async fn fetch( &self, url: impl Into<String>, init: Option<RequestInit> ) -> Result<HttpResponse>
Invoke a fetch event in a worker with a url and optionally a RequestInit.
Return type is Response
unless http
feature is enabled
and then it is http::Response<worker::Body>
.
sourcepub async fn fetch_request(&self, request: HttpRequest) -> Result<HttpResponse>
pub async fn fetch_request(&self, request: HttpRequest) -> Result<HttpResponse>
Invoke a fetch event with an existing Request.
Argument type is Request
unless http
feature is enabled
and then it is http::Request<worker::Body>
.
Return type is Response
unless http
feature is enabled
and then it is http::Response<worker::Body>
.
sourcepub fn into_rpc<T: JsCast>(self) -> T
pub fn into_rpc<T: JsCast>(self) -> T
Convert Fetcher into user-defined RPC interface.
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends=js_sys::Object)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub type MyRpcInterface;
#[wasm_bindgen(method, catch)]
pub fn add(
this: &MyRpcInterface,
a: u32,
b: u32,
) -> std::result::Result<js_sys::Promise, JsValue>;
}
let rpc: MyRpcInterface = fetcher.into_rpc();
let result = rpc.add(1, 2);
Trait Implementations§
source§impl EnvBinding for Fetcher
impl EnvBinding for Fetcher
source§impl JsCast for Fetcher
impl JsCast for Fetcher
source§fn instanceof(val: &JsValue) -> bool
fn instanceof(val: &JsValue) -> bool
Performs a dynamic
instanceof
check to see whether the JsValue
provided is an instance of this type. Read moresource§fn unchecked_from_js(val: JsValue) -> Self
fn unchecked_from_js(val: JsValue) -> Self
source§fn unchecked_from_js_ref(val: &JsValue) -> &Self
fn unchecked_from_js_ref(val: &JsValue) -> &Self
source§fn has_type<T>(&self) -> boolwhere
T: JsCast,
fn has_type<T>(&self) -> boolwhere
T: JsCast,
Test whether this JS value has a type
T
. Read moresource§fn dyn_into<T>(self) -> Result<T, Self>where
T: JsCast,
fn dyn_into<T>(self) -> Result<T, Self>where
T: JsCast,
Performs a dynamic cast (checked at runtime) of this value into the
target type
T
. Read moresource§fn dyn_ref<T>(&self) -> Option<&T>where
T: JsCast,
fn dyn_ref<T>(&self) -> Option<&T>where
T: JsCast,
Performs a dynamic cast (checked at runtime) of this value into the
target type
T
. Read moresource§fn unchecked_into<T>(self) -> Twhere
T: JsCast,
fn unchecked_into<T>(self) -> Twhere
T: JsCast,
Performs a zero-cost unchecked cast into the specified type. Read more
source§fn unchecked_ref<T>(&self) -> &Twhere
T: JsCast,
fn unchecked_ref<T>(&self) -> &Twhere
T: JsCast,
Performs a zero-cost unchecked cast into a reference to the specified
type. Read more
Auto Trait Implementations§
impl Freeze for Fetcher
impl RefUnwindSafe for Fetcher
impl Send for Fetcher
impl Sync for Fetcher
impl Unpin for Fetcher
impl UnwindSafe for Fetcher
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more