Skip to main content

Intent

Struct Intent 

Source
pub struct Intent {
    pub name: &'static str,
    pub source: IntentSource,
    /* private fields */
}
Expand description

A runtime intent dispatched through the widget tree.

The name is the stable dispatch key (matched against Action::intent). The optional payload carries any type the sender wants to attach — recover it with Intent::payload::<T> when the handler knows the expected type (typically via IntentKind::from_intent).

The source field records where the intent originated — set by the framework’s standard activation paths (button taps, menu selects, shortcut chords, gesture recognizers) so analytics can answer “which surface drives this intent?”. See crate::telemetry::IntentSource.

Fields§

§name: &'static str

Stable intent name. Usually matches the originating Shortcut’s intent_name().

§source: IntentSource

Origin of the intent. The framework’s activation paths (button, menu, shortcut, gesture) set this; programmatic callers default to Programmatic via Intent::new. Read by the dispatch-tap to fill the source prop on intent.dispatched events.

Implementations§

Source§

impl Intent

Source

pub fn new(name: &'static str) -> Self

A parameter-less intent. Defaults to IntentSource::Programmatic; framework activation paths override via Intent::with_source before dispatching.

Source

pub fn with_payload<T: 'static>(name: &'static str, payload: T) -> Self

An intent carrying a typed payload. The payload is stored type-erased in an Rc<dyn Any>; recover it with Intent::payload.

Source

pub fn with_source(self, source: IntentSource) -> Self

Tag the intent with its origin. Called by framework activation wrappers (button on_activate, menu on_select, shortcut activation, gesture on_recognized) right before dispatch. App code typically doesn’t call this directly — use EventContext::send_intent from inside the right handler and the source is set automatically.

(Note: EventContext::send_intent infers the source from the handler context where possible; this method is the escape hatch for callers that need to override.)

Source

pub fn payload<T: 'static>(&self) -> Option<&T>

Borrow the payload as &T, or None if the intent has no payload or the payload’s concrete type doesn’t match.

Source

pub fn has_payload(&self) -> bool

Whether this intent carries any payload (typed or not).

Trait Implementations§

Source§

impl Clone for Intent

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

impl Debug for Intent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: IntentKind> From<K> for Intent

Blanket conversion from any IntentKind into a runtime Intent.

Lets call sites drop the explicit .into_intent() hop where an Into<Intent> bound is available (for example, EventContext::send_intent and ShortcutBuilder::on_activate).

Source§

fn from(kind: K) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Intent

§

impl !Send for Intent

§

impl !Sync for Intent

§

impl !UnwindSafe for Intent

§

impl Freeze for Intent

§

impl Unpin for Intent

§

impl UnsafeUnpin for Intent

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, 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> 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, <T as TryFrom<U>>::Error>

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.