Skip to main content

WireContext

Struct WireContext 

Source
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

Source

pub fn new(parts: Parts) -> Self

Create a WireContext from Axum request parts.

Source

pub fn empty() -> Self

Create an empty WireContext (used when no request context is available, e.g. sub-component mounts from html!).

Source

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();
Source

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)>();
Source

pub fn query<T>(&self) -> Query<T>
where T: DeserializeOwned + Send + 'static,

Extract query parameters. Panics on failure.

ⓘ
let Query(params) = ctx.query::<Pagination>();
Source

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>();
Source

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>();
Source

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.

Source

pub fn try_query<T>(&self) -> Result<Query<T>, QueryRejection>
where T: DeserializeOwned + Send + 'static,

Try to extract query parameters.

Source

pub fn try_state<T: Clone + Send + Sync + 'static>(&self) -> Option<T>

Try to get shared application state by type.

Source

pub fn try_extension<T: Clone + Send + Sync + 'static>(&self) -> Option<T>

Try to get a request extension by type.

Source

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.

Source

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>().

Source

pub fn cookie_jar(&self) -> CookieJar

Build a plain cookie jar from request headers.

Build a signed cookie jar from request headers using the provided key.

Source

pub fn set_response_extension<T>(&self, value: T)
where T: Clone + Send + Sync + 'static,

Queue a response extension to be inserted into the HTTP response.

Source

pub fn dispatch(&self, name: &str)

Dispatch a browser event from the component root.

Source

pub fn dispatch_with<T: Serialize>(&self, name: &str, detail: T)

Dispatch a browser event with a JSON detail payload.

Source

pub fn dispatch_self(&self, name: &str)

Dispatch a browser event to this component root only.

Source

pub fn dispatch_self_with<T: Serialize>(&self, name: &str, detail: T)

Dispatch a browser event with detail to this component root only.

Source

pub fn dispatch_to(&self, component: &str, name: &str)

Dispatch a browser event to all mounted components with the given wire name.

Source

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.

Trait Implementations§

Source§

impl Clone for WireContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more