pub struct DeviceType { /* private fields */ }
Expand description
Whether a particular device is an input device (e.g. a microphone), or an output device (e.g. headphones).
Implementations§
Source§impl DeviceType
impl DeviceType
pub const INPUT: DeviceType
pub const OUTPUT: DeviceType
Sourcepub const fn empty() -> DeviceType
pub const fn empty() -> DeviceType
Returns an empty set of flags.
Sourcepub const fn all() -> DeviceType
pub const fn all() -> DeviceType
Returns the set containing all flags.
Sourcepub const fn from_bits(bits: u32) -> Option<DeviceType>
pub const fn from_bits(bits: u32) -> Option<DeviceType>
Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag.
Sourcepub const fn from_bits_truncate(bits: u32) -> DeviceType
pub const fn from_bits_truncate(bits: u32) -> DeviceType
Convert from underlying bit representation, dropping any bits that do not correspond to flags.
Sourcepub const unsafe fn from_bits_unchecked(bits: u32) -> DeviceType
pub const unsafe fn from_bits_unchecked(bits: u32) -> DeviceType
Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).
§Safety
The caller of the bitflags!
macro can chose to allow or
disallow extra bits for their bitflags type.
The caller of from_bits_unchecked()
has to ensure that
all bits correspond to a defined flag or that extra bits
are valid for this bitflags type.
Sourcepub const fn intersects(&self, other: DeviceType) -> bool
pub const fn intersects(&self, other: DeviceType) -> bool
Returns true
if there are flags common to both self
and other
.
Sourcepub const fn contains(&self, other: DeviceType) -> bool
pub const fn contains(&self, other: DeviceType) -> bool
Returns true
if all of the flags in other
are contained within self
.
Examples found in repository?
15fn print_device_info(info: &cubeb::DeviceInfo) {
16 let devtype = if info.device_type().contains(DeviceType::INPUT) {
17 "input"
18 } else if info.device_type().contains(DeviceType::OUTPUT) {
19 "output"
20 } else {
21 "unknown?"
22 };
23
24 let devstate = match info.state() {
25 cubeb::DeviceState::Disabled => "disabled",
26 cubeb::DeviceState::Unplugged => "unplugged",
27 cubeb::DeviceState::Enabled => "enabled",
28 };
29
30 let devdeffmt = match info.default_format() {
31 DeviceFormat::S16LE => "S16LE",
32 DeviceFormat::S16BE => "S16BE",
33 DeviceFormat::F32LE => "F32LE",
34 DeviceFormat::F32BE => "F32BE",
35 _ => "unknown?",
36 };
37
38 let mut devfmts = "".to_string();
39 if info.format().contains(DeviceFormat::S16LE) {
40 devfmts = format!("{} S16LE", devfmts);
41 }
42 if info.format().contains(DeviceFormat::S16BE) {
43 devfmts = format!("{} S16BE", devfmts);
44 }
45 if info.format().contains(DeviceFormat::F32LE) {
46 devfmts = format!("{} F32LE", devfmts);
47 }
48 if info.format().contains(DeviceFormat::F32BE) {
49 devfmts = format!("{} F32BE", devfmts);
50 }
51
52 if let Some(device_id) = info.device_id() {
53 let preferred = if info.preferred().is_empty() {
54 ""
55 } else {
56 " (PREFERRED)"
57 };
58 println!("dev: \"{}\"{}", device_id, preferred);
59 }
60 if let Some(friendly_name) = info.friendly_name() {
61 println!("\tName: \"{}\"", friendly_name);
62 }
63 if let Some(group_id) = info.group_id() {
64 println!("\tGroup: \"{}\"", group_id);
65 }
66 if let Some(vendor_name) = info.vendor_name() {
67 println!("\tVendor: \"{}\"", vendor_name);
68 }
69 println!("\tType: {}", devtype);
70 println!("\tState: {}", devstate);
71 println!("\tCh: {}", info.max_channels());
72 println!(
73 "\tFormat: {} (0x{:x}) (default: {})",
74 &devfmts[1..],
75 info.format(),
76 devdeffmt
77 );
78 println!(
79 "\tRate: {} - {} (default: {})",
80 info.min_rate(),
81 info.max_rate(),
82 info.default_rate()
83 );
84 println!(
85 "\tLatency: lo {} frames, hi {} frames",
86 info.latency_lo(),
87 info.latency_hi()
88 );
89}
Sourcepub fn insert(&mut self, other: DeviceType)
pub fn insert(&mut self, other: DeviceType)
Inserts the specified flags in-place.
Sourcepub fn remove(&mut self, other: DeviceType)
pub fn remove(&mut self, other: DeviceType)
Removes the specified flags in-place.
Sourcepub fn toggle(&mut self, other: DeviceType)
pub fn toggle(&mut self, other: DeviceType)
Toggles the specified flags in-place.
Sourcepub fn set(&mut self, other: DeviceType, value: bool)
pub fn set(&mut self, other: DeviceType, value: bool)
Inserts or removes the specified flags depending on the passed value.
Sourcepub const fn intersection(self, other: DeviceType) -> DeviceType
pub const fn intersection(self, other: DeviceType) -> DeviceType
Returns the intersection between the flags in self
and
other
.
Specifically, the returned set contains only the flags which are
present in both self
and other
.
This is equivalent to using the &
operator (e.g.
ops::BitAnd
), as in flags & other
.
Sourcepub const fn union(self, other: DeviceType) -> DeviceType
pub const fn union(self, other: DeviceType) -> DeviceType
Returns the union of between the flags in self
and other
.
Specifically, the returned set contains all flags which are
present in either self
or other
, including any which are
present in both (see Self::symmetric_difference
if that
is undesirable).
This is equivalent to using the |
operator (e.g.
ops::BitOr
), as in flags | other
.
Sourcepub const fn difference(self, other: DeviceType) -> DeviceType
pub const fn difference(self, other: DeviceType) -> DeviceType
Returns the difference between the flags in self
and other
.
Specifically, the returned set contains all flags present in
self
, except for the ones present in other
.
It is also conceptually equivalent to the “bit-clear” operation:
flags & !other
(and this syntax is also supported).
This is equivalent to using the -
operator (e.g.
ops::Sub
), as in flags - other
.
Sourcepub const fn symmetric_difference(self, other: DeviceType) -> DeviceType
pub const fn symmetric_difference(self, other: DeviceType) -> DeviceType
Returns the symmetric difference between the flags
in self
and other
.
Specifically, the returned set contains the flags present which
are present in self
or other
, but that are not present in
both. Equivalently, it contains the flags present in exactly
one of the sets self
and other
.
This is equivalent to using the ^
operator (e.g.
ops::BitXor
), as in flags ^ other
.
Sourcepub const fn complement(self) -> DeviceType
pub const fn complement(self) -> DeviceType
Returns the complement of this set of flags.
Specifically, the returned set contains all the flags which are
not set in self
, but which are allowed for this type.
Alternatively, it can be thought of as the set difference
between Self::all()
and self
(e.g. Self::all() - self
)
This is equivalent to using the !
operator (e.g.
ops::Not
), as in !flags
.
Source§impl DeviceType
impl DeviceType
pub const UNKNOWN: DeviceType
Trait Implementations§
Source§impl Binary for DeviceType
impl Binary for DeviceType
Source§impl BitAnd for DeviceType
impl BitAnd for DeviceType
Source§fn bitand(self, other: DeviceType) -> DeviceType
fn bitand(self, other: DeviceType) -> DeviceType
Returns the intersection between the two sets of flags.
Source§type Output = DeviceType
type Output = DeviceType
&
operator.Source§impl BitAndAssign for DeviceType
impl BitAndAssign for DeviceType
Source§fn bitand_assign(&mut self, other: DeviceType)
fn bitand_assign(&mut self, other: DeviceType)
Disables all flags disabled in the set.
Source§impl BitOr for DeviceType
impl BitOr for DeviceType
Source§fn bitor(self, other: DeviceType) -> DeviceType
fn bitor(self, other: DeviceType) -> DeviceType
Returns the union of the two sets of flags.
Source§type Output = DeviceType
type Output = DeviceType
|
operator.Source§impl BitOrAssign for DeviceType
impl BitOrAssign for DeviceType
Source§fn bitor_assign(&mut self, other: DeviceType)
fn bitor_assign(&mut self, other: DeviceType)
Adds the set of flags.
Source§impl BitXor for DeviceType
impl BitXor for DeviceType
Source§fn bitxor(self, other: DeviceType) -> DeviceType
fn bitxor(self, other: DeviceType) -> DeviceType
Returns the left flags, but with all the right flags toggled.
Source§type Output = DeviceType
type Output = DeviceType
^
operator.Source§impl BitXorAssign for DeviceType
impl BitXorAssign for DeviceType
Source§fn bitxor_assign(&mut self, other: DeviceType)
fn bitxor_assign(&mut self, other: DeviceType)
Toggles the set of flags.
Source§impl Clone for DeviceType
impl Clone for DeviceType
Source§fn clone(&self) -> DeviceType
fn clone(&self) -> DeviceType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DeviceType
impl Debug for DeviceType
Source§impl Extend<DeviceType> for DeviceType
impl Extend<DeviceType> for DeviceType
Source§fn extend<T>(&mut self, iterator: T)where
T: IntoIterator<Item = DeviceType>,
fn extend<T>(&mut self, iterator: T)where
T: IntoIterator<Item = DeviceType>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl FromIterator<DeviceType> for DeviceType
impl FromIterator<DeviceType> for DeviceType
Source§fn from_iter<T>(iterator: T) -> DeviceTypewhere
T: IntoIterator<Item = DeviceType>,
fn from_iter<T>(iterator: T) -> DeviceTypewhere
T: IntoIterator<Item = DeviceType>,
Source§impl Hash for DeviceType
impl Hash for DeviceType
Source§impl LowerHex for DeviceType
impl LowerHex for DeviceType
Source§impl Not for DeviceType
impl Not for DeviceType
Source§fn not(self) -> DeviceType
fn not(self) -> DeviceType
Returns the complement of this set of flags.
Source§type Output = DeviceType
type Output = DeviceType
!
operator.Source§impl Octal for DeviceType
impl Octal for DeviceType
Source§impl Ord for DeviceType
impl Ord for DeviceType
Source§fn cmp(&self, other: &DeviceType) -> Ordering
fn cmp(&self, other: &DeviceType) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for DeviceType
impl PartialEq for DeviceType
Source§impl PartialOrd for DeviceType
impl PartialOrd for DeviceType
Source§impl Sub for DeviceType
impl Sub for DeviceType
Source§fn sub(self, other: DeviceType) -> DeviceType
fn sub(self, other: DeviceType) -> DeviceType
Returns the set difference of the two sets of flags.
Source§type Output = DeviceType
type Output = DeviceType
-
operator.Source§impl SubAssign for DeviceType
impl SubAssign for DeviceType
Source§fn sub_assign(&mut self, other: DeviceType)
fn sub_assign(&mut self, other: DeviceType)
Disables all flags enabled in the set.