pub struct DeviceId(pub HostId, pub String);Expand description
A stable identifier for an audio device across all supported platforms.
Device IDs should remain stable across application restarts and can be serialized using Display/FromStr.
A device ID consists of a HostId identifying the audio backend and a device-specific identifier string.
§Example
use cpal::traits::{HostTrait, DeviceTrait};
use cpal::DeviceId;
use std::str::FromStr;
let host = cpal::default_host();
let device = host.default_output_device().unwrap();
let device_id = device.id().unwrap();
// Serialize to string (e.g., for storage in config file)
let id_string = device_id.to_string();
println!("Device ID: {}", id_string); // e.g., "wasapi:device_identifier"
// Deserialize from string
match DeviceId::from_str(&id_string) {
Ok(parsed_id) => {
// Retrieve the device by its ID
if let Some(device) = host.device_by_id(&parsed_id) {
println!("Found device: {:?}", device.id());
}
}
Err(e) => eprintln!("Failed to parse device ID: {}", e),
}Tuple Fields§
§0: HostId§1: StringTrait Implementations§
impl Eq for DeviceId
impl StructuralPartialEq for DeviceId
Auto Trait Implementations§
impl Freeze for DeviceId
impl RefUnwindSafe for DeviceId
impl Send for DeviceId
impl Sync for DeviceId
impl Unpin for DeviceId
impl UnsafeUnpin for DeviceId
impl UnwindSafe for DeviceId
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
Mutably borrows from an owned value. Read more