pub struct WireContext { /* private fields */ }Expand description
Request context available to wire components.
In mount(ctx: WireContext), the context is passed directly.
In render() and actions, use self.ctx() to access the task-local context.
Provides convenience shortcuts for common extractors (path, query,
state, extension) and a general-purpose extract::<T>() for anything
that implements FromRequestParts<()>.
Implementations§
Source§impl WireContext
impl WireContext
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty WireContext (used when no request context is available,
e.g. sub-component mounts from html!).
Sourcepub async fn extract<T>(&self) -> Result<T, T::Rejection>where
T: FromRequestParts<()>,
pub async fn extract<T>(&self) -> Result<T, T::Rejection>where
T: FromRequestParts<()>,
Extract any type that implements FromRequestParts<()>.
let headers = ctx.extract::<HeaderMap>().await.unwrap();Sourcepub fn path<T>(&self) -> Path<T>where
T: DeserializeOwned + Send + 'static,
pub fn path<T>(&self) -> Path<T>where
T: DeserializeOwned + Send + 'static,
Extract path parameters. Panics on failure.
let Path(post_id) = ctx.path::<u64>();
let Path((org, repo)) = ctx.path::<(String, String)>();Sourcepub fn query<T>(&self) -> Query<T>where
T: DeserializeOwned + Send + 'static,
pub fn query<T>(&self) -> Query<T>where
T: DeserializeOwned + Send + 'static,
Extract query parameters. Panics on failure.
let Query(params) = ctx.query::<Pagination>();Sourcepub fn state<T: Clone + Send + Sync + 'static>(&self) -> T
pub fn state<T: Clone + Send + Sync + 'static>(&self) -> T
Get shared application state by type. Panics if not found.
State is added via WireApp::state(value) or Extension(value) layer.
let db = ctx.state::<DatabasePool>();Sourcepub fn extension<T: Clone + Send + Sync + 'static>(&self) -> T
pub fn extension<T: Clone + Send + Sync + 'static>(&self) -> T
Get a request extension by type. Panics if not found.
let flags = ctx.extension::<FeatureFlags>();Sourcepub fn try_path<T>(&self) -> Result<Path<T>, PathRejection>where
T: DeserializeOwned + Send + 'static,
pub fn try_path<T>(&self) -> Result<Path<T>, PathRejection>where
T: DeserializeOwned + Send + 'static,
Try to extract path parameters.
During the initial page load, this uses Axum’s native Path<T> extractor.
During AJAX updates, it falls back to stored path params from the snapshot.
Sourcepub fn try_query<T>(&self) -> Result<Query<T>, QueryRejection>where
T: DeserializeOwned + Send + 'static,
pub fn try_query<T>(&self) -> Result<Query<T>, QueryRejection>where
T: DeserializeOwned + Send + 'static,
Try to extract query parameters.
Sourcepub fn try_state<T: Clone + Send + Sync + 'static>(&self) -> Option<T>
pub fn try_state<T: Clone + Send + Sync + 'static>(&self) -> Option<T>
Try to get shared application state by type.
Sourcepub fn try_extension<T: Clone + Send + Sync + 'static>(&self) -> Option<T>
pub fn try_extension<T: Clone + Send + Sync + 'static>(&self) -> Option<T>
Try to get a request extension by type.
Sourcepub fn is_wire_request(&self) -> bool
pub fn is_wire_request(&self) -> bool
Returns true if this request originated from an AJAX wire update
(POST /_wire/update), i.e. a subsequent action/refresh call — not the
initial page load.
Sourcepub fn insert_extension<T: Clone + Send + Sync + 'static>(&self, val: T)
pub fn insert_extension<T: Clone + Send + Sync + 'static>(&self, val: T)
Insert a value into the request extensions. Useful for adding custom
data accessible via ctx.extension::<T>().
Build a plain cookie jar from request headers.
Build a signed cookie jar from request headers using the provided key.
Sourcepub fn set_response_extension<T>(&self, value: T)
pub fn set_response_extension<T>(&self, value: T)
Queue a response extension to be inserted into the HTTP response.
Sourcepub fn dispatch_with<T: Serialize>(&self, name: &str, detail: T)
pub fn dispatch_with<T: Serialize>(&self, name: &str, detail: T)
Dispatch a browser event with a JSON detail payload.
Sourcepub fn dispatch_self(&self, name: &str)
pub fn dispatch_self(&self, name: &str)
Dispatch a browser event to this component root only.
Sourcepub fn dispatch_self_with<T: Serialize>(&self, name: &str, detail: T)
pub fn dispatch_self_with<T: Serialize>(&self, name: &str, detail: T)
Dispatch a browser event with detail to this component root only.
Sourcepub fn dispatch_to(&self, component: &str, name: &str)
pub fn dispatch_to(&self, component: &str, name: &str)
Dispatch a browser event to all mounted components with the given wire name.
Sourcepub fn dispatch_to_with<T: Serialize>(
&self,
component: &str,
name: &str,
detail: T,
)
pub fn dispatch_to_with<T: Serialize>( &self, component: &str, name: &str, detail: T, )
Dispatch a browser event with detail to all mounted components with the given wire name.
Queue a plain cookie to be set on the HTTP response.
Queue a plain cookie removal on the HTTP response.
Queue a signed cookie set on the HTTP response.
Queue a signed cookie removal on the HTTP response.