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 strStable intent name. Usually matches the originating
Shortcut’s intent_name().
source: IntentSourceOrigin 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
impl Intent
Sourcepub fn new(name: &'static str) -> Self
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.
Sourcepub fn with_payload<T: 'static>(name: &'static str, payload: T) -> Self
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.
Sourcepub fn with_source(self, source: IntentSource) -> Self
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.)
Sourcepub fn payload<T: 'static>(&self) -> Option<&T>
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.
Sourcepub fn has_payload(&self) -> bool
pub fn has_payload(&self) -> bool
Whether this intent carries any payload (typed or not).
Trait Implementations§
Source§impl<K: IntentKind> From<K> for Intent
Blanket conversion from any IntentKind into a runtime Intent.
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).