pub trait Beep {
// Required method
fn beep(&mut self, hertz: u16) -> Result<()>;
// Provided methods
fn note(&mut self, note: &Note) -> Result<()> { ... }
fn play<T>(&mut self, melody: T) -> Result<()>
where T: AsRef<[Note]> { ... }
}
Expand description
Allows to beep the PC speaker.
Required Methods§
Sourcefn beep(&mut self, hertz: u16) -> Result<()>
fn beep(&mut self, hertz: u16) -> Result<()>
Beep the PC speaker at the given frequency.
§Errors
Returns an [Error
] if beeping the PC speaker fails.
§Examples
use beep_evdev::{Beep, DEFAULT_FILE};
use std::{thread, time};
use evdev::Device;
let mut pcspkr = Device::open(DEFAULT_FILE).unwrap();
pcspkr.beep(440).expect("could not beep");
thread::sleep(time::Duration::from_millis(500));
pcspkr.beep(880).expect("could not beep");
thread::sleep(time::Duration::from_millis(500));
pcspkr.beep(0).expect("could not beep");
Provided Methods§
Sourcefn play<T>(&mut self, melody: T) -> Result<()>
fn play<T>(&mut self, melody: T) -> Result<()>
Play the given melody on the PC speaker.
§Errors
Returns an [Error
] if beeping the PC speaker fails.
§Examples
use evdev::Device;
use beep_evdev::{Beep, Note, DEFAULT_FILE};
let melody = vec![
(659, 120).into(),
(622, 120).into(),
(659, 120).into(),
(622, 120).into(),
(659, 120).into(),
(94, 120).into(),
(587, 120).into(),
(523, 120).into(),
(440, 120).into(),
(262, 120).into(),
(330, 120).into(),
(440, 120).into(),
(494, 120).into(),
(330, 120).into(),
(415, 120).into(),
(494, 120).into(),
(523, 120).into(),
(330, 120).into(),
(659, 120).into(),
(622, 120).into(),
(659, 120).into(),
(622, 120).into(),
(659, 120).into(),
(494, 120).into(),
(587, 120).into(),
(523, 120).into(),
(440, 120).into(),
(262, 120).into(),
(330, 120).into(),
(440, 120).into(),
(494, 120).into(),
(330, 120).into(),
(523, 120).into(),
(494, 120).into(),
(440, 120).into(),
];
Device::open(DEFAULT_FILE)
.expect("could not open pcspkr device")
.play(&melody)
.expect("could not play melody :-(");
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.