pub struct MaterialHaptics;Expand description
The design system’s pluggable, process-global haptics seam. Carries no
state of its own — every method is a plain associated function over one
process-wide hook cell. See the module docs for why this crate
reaches no frust-haptics dependency itself.
Implementations§
Source§impl MaterialHaptics
impl MaterialHaptics
Sourcepub fn set(hook: fn(HapticSignal)) -> bool
pub fn set(hook: fn(HapticSignal)) -> bool
Install the process-wide haptics hook.
Timing contract: intended to be called once, from an app’s own
install()-era setup (mirroring how crate::install seeds the
default theme) — before any widget can call Self::fire. The
underlying cell is set-once: the first successful call wins, and
every later call is rejected outright — a hook swap (last-wins) is
deliberately not supported, so there is no way to uninstall or
replace a hook once one has won. Returns true iff this call
installed the hook, false if a hook was already installed and this
one was rejected.
§Wiring to frust-haptics
frust-material never depends on frust-haptics (or any other
plugin) itself — the design-system charter forbids a plugin-tier
crate depending on a sibling plugin (docs/PLUGINS_ARCHITECTURE.md’s
Layer Dependencies). An app that wants real haptic feedback depends
on frust-haptics itself and wires it here — this example is
ignored (not no_run) because frust-haptics is intentionally
absent from this crate’s own dependency graph, including as a
dev-dependency, so it cannot compile in this doctest:
// In the app's own crate — frust-haptics is *its* dependency, never
// frust-material's.
fn install_haptics() {
frust_material::MaterialHaptics::set(|signal| {
use frust_material::HapticSignal;
use frust_haptics::{HapticEffect, Haptics};
let effect = match signal {
HapticSignal::None => return,
HapticSignal::Light => HapticEffect::ImpactLight,
HapticSignal::Medium => HapticEffect::ImpactMedium,
HapticSignal::Heavy => HapticEffect::ImpactHeavy,
HapticSignal::SliderTick => HapticEffect::SelectionClick,
};
let _ = Haptics::perform(effect);
});
}Sourcepub fn fire(signal: HapticSignal)
pub fn fire(signal: HapticSignal)
Fire signal through the installed hook — a silent no-op if none
has been installed yet (the default; see the module docs).
Auto Trait Implementations§
impl Freeze for MaterialHaptics
impl RefUnwindSafe for MaterialHaptics
impl Send for MaterialHaptics
impl Sync for MaterialHaptics
impl Unpin for MaterialHaptics
impl UnsafeUnpin for MaterialHaptics
impl UnwindSafe for MaterialHaptics
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.