pub struct WasmLayer { /* private fields */ }Expand description
WebAssembly middleware. See the module docs.
Implementations§
Source§impl WasmLayer
impl WasmLayer
Sourcepub fn new(name: impl Into<String>, wasm: &[u8]) -> Result<WasmLayer, String>
pub fn new(name: impl Into<String>, wasm: &[u8]) -> Result<WasmLayer, String>
Compile wasm (binary module bytes) as plugin name. Refused: a
module that imports anything, or lacks memory, rws_alloc or
rws_on_request of the right types.
Sourcepub fn from_file(path: &str) -> Result<WasmLayer, String>
pub fn from_file(path: &str) -> Result<WasmLayer, String>
Self::new from a .wasm file; the plugin is named after it.
Sourcepub fn fuel(self, fuel: u64) -> WasmLayer
pub fn fuel(self, fuel: u64) -> WasmLayer
Fuel per hook call (default DEFAULT_FUEL).
Sourcepub fn memory_mb(self, mb: u64) -> WasmLayer
pub fn memory_mb(self, mb: u64) -> WasmLayer
Linear memory limit in MiB (default DEFAULT_MEMORY_MB).
pub fn name(&self) -> &str
Sourcepub fn on_request(
&self,
request: &Request,
connection: &ConnectionInfo,
) -> Result<RequestAction, PluginError>
pub fn on_request( &self, request: &Request, connection: &ConnectionInfo, ) -> Result<RequestAction, PluginError>
Run the request hook on its own (for tests and embedders).
Trait Implementations§
Source§impl Middleware for WasmLayer
impl Middleware for WasmLayer
Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
Headers only: a streamed request body passes through untouched.
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
true when this layer’s own work for request never blocks (in-memory
state, atomics, short mutexes) — see Application::runs_inline. A
WithMiddleware stack runs inline only if every layer and the inner
application agree. Default false.Source§fn is_passthrough(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn is_passthrough( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when handle would do nothing for request but call next
(e.g. a rate limit that isn’t configured). A WithMiddleware stack
offers the inner application’s execute_async only if every layer
passes the request through. Default false.Source§fn answers_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn answers_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer answers request itself — it doesn’t call
next — and reads its body as a stream (a proxy forwarding it as it
arrives). The body is then streamed whatever the layers after it and
the application would say. Requires accepts_streamed_body. Since
18.3.0.Source§fn layer_name(&self) -> &'static str
fn layer_name(&self) -> &'static str
A short name for this layer, as tools that describe an app list it
(
Application::middleware_names): by default the type’s name
without its module path or generic parameters (CacheLayer). Since
18.28.0.Auto Trait Implementations§
impl !RefUnwindSafe for WasmLayer
impl !UnwindSafe for WasmLayer
impl Freeze for WasmLayer
impl Send for WasmLayer
impl Sync for WasmLayer
impl Unpin for WasmLayer
impl UnsafeUnpin for WasmLayer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more