pub trait Haptics: Send + Sync {
// Required method
fn perform(&self, feedback: HapticFeedback);
// Provided methods
fn vibrate(&self, duration_ms: u32, amplitude: u8) { ... }
fn play_pattern(&self, pattern: &HapticPattern) { ... }
fn perform_effect(&self, effect: HapticEffect) { ... }
fn cancel(&self) { ... }
fn has_amplitude_control(&self) -> bool { ... }
}Expand description
Re-export framework services (HTTP, URI, etc.) from the dedicated services crate. Performs haptic feedback. Installed by the platform backend; the default is a no-op.
Only perform has to be implemented. Every other method
falls back to it, so extending this trait cannot break an existing backend.
Required Methods§
Sourcefn perform(&self, feedback: HapticFeedback)
fn perform(&self, feedback: HapticFeedback)
Plays a semantic feedback event.
Provided Methods§
Sourcefn vibrate(&self, duration_ms: u32, amplitude: u8)
fn vibrate(&self, duration_ms: u32, amplitude: u8)
Vibrates once for duration_ms at amplitude (1 to 255; 0 means the
device default strength).
Maps to VibrationEffect.createOneShot(long, int) on Android. The
defaulted body picks the closest HapticFeedback constant.
Sourcefn play_pattern(&self, pattern: &HapticPattern)
fn play_pattern(&self, pattern: &HapticPattern)
Plays a waveform pattern.
Maps to VibrationEffect.createWaveform(long[], int[], int) on Android.
The defaulted body plays HapticPattern::closest_feedback once.
Sourcefn perform_effect(&self, effect: HapticEffect)
fn perform_effect(&self, effect: HapticEffect)
Plays a system-defined primitive.
Maps to VibrationEffect.createPredefined(int) on Android. The
defaulted body plays HapticEffect::closest_feedback.
Sourcefn cancel(&self)
fn cancel(&self)
Stops any vibration in progress, including a repeating waveform. Backends with no way to cancel leave this as a no-op.
Sourcefn has_amplitude_control(&self) -> bool
fn has_amplitude_control(&self) -> bool
Whether the device reproduces amplitudes rather than treating every non-zero level as full strength.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".