Skip to main content

HapticRequest

Struct HapticRequest 

Source
#[repr(C)]
pub struct HapticRequest { pub pattern: HapticPattern, pub target: HapticTarget, pub intensity: f32, pub duration_ms: u32, }
Expand description

A queued haptic request.

Queued rather than played synchronously because a callback runs on the layout thread, and the platform APIs that drive actuators want to be called from the event loop — the same reason clipboard writes and menu opens are deferred.

Fields§

§pattern: HapticPattern§target: HapticTarget§intensity: f32

Strength scale in 0.0..=1.0, where 1.0 is the platform’s own default strength for the pattern.

Portable because three of the four backends take a scale natively: Android’s composition primitives take a float scale, iOS’s impactOccurred(intensity:) takes one, and gamepad rumble IS an amplitude. macOS is the exception — NSHapticFeedbackPattern has no strength axis at all, so the value is ignored there rather than emulated, because faking it with repeated taps feels like a stutter.

§duration_ms: u32

How long the effect should last, in milliseconds. 0 means “the pattern’s own natural duration”, which is what every tap-style actuator wants.

Only meaningful for continuous actuators — gamepad rumble motors, which run until told to stop. Tap-style actuators ignore it.

Implementations§

Source§

impl HapticRequest

Source

pub const fn new(pattern: HapticPattern, target: HapticTarget) -> Self

A request at full strength and natural duration — the common case.

Source

pub fn intensity_clamped(&self) -> f32

Clamp the scale into the range every backend assumes.

Callers compute intensity from things like drag velocity, so an out-of-range or NaN value is expected rather than exceptional; a NaN reaching Android’s addPrimitive throws.

Source

pub fn rumble_duration_ms(&self) -> u32

How long a CONTINUOUS actuator should run, in milliseconds.

duration_ms == 0 means “the pattern’s natural duration”, which for a tap-style actuator is whatever the platform does and for a MOTOR is not zero: a rumble of zero length is not something a person can feel. 150ms is gilrs’s own example figure and about the shortest pulse an ERM motor can spin up and down within.

Shared rather than repeated per backend: the gilrs path and the Android per-controller vibrator answer the same question, and two copies of a magic number drift.

Source

pub fn wants_strong_motor(&self) -> bool

Which MOTOR this pattern belongs on, not how hard to drive it.

A controller has a low-frequency motor that THUDS and a high-frequency one that BUZZES, and the pattern picks between them. Driving both together is a different, muddier sensation rather than a louder one - which is why this is a bool and not a mix.

true = the strong (low-frequency) motor.

Source

pub fn amplitude_u8(&self) -> u8

The intensity as an 8-bit amplitude in 1..=255.

Android’s VibrationEffect.createOneShot takes amplitude in that range, where 0 is not “silent” but INVALID - it throws IllegalArgumentException. A caller that wants silence must not play at all, so this floors at 1 and the backend checks for a zero intensity before calling.

Trait Implementations§

Source§

impl Clone for HapticRequest

Source§

fn clone(&self) -> HapticRequest

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 Copy for HapticRequest

Source§

impl Debug for HapticRequest

Source§

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

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

impl PartialEq for HapticRequest

Source§

fn eq(&self, other: &HapticRequest) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HapticRequest

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, 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, !>

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.