pub struct AttributeSet { /* private fields */ }Expand description
Set of attributes for use in request masks. Can represent single or multiple attributes combined with bitwise OR.
Implementations§
Source§impl AttributeSet
impl AttributeSet
pub const fn empty() -> Self
Sourcepub const fn from_raw(mask: u16) -> Self
pub const fn from_raw(mask: u16) -> Self
Build a set from a raw wire mask.
The header field is 15 bits wide, so bit 15 is dropped rather than silently lost later during serialization.
Sourcepub fn single(attr: Attribute) -> Self
pub fn single(attr: Attribute) -> Self
Examples found in repository?
examples/calibration_auth.rs (line 19)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8 let initial_level = device.state().map(|state| state.auth_level).unwrap_or(0);
9 println!("Initial authentication level: {initial_level}");
10
11 let result = device.authenticate_calibration().await?;
12 println!(
13 "Calibration authentication level: {} (attribute 0x{:04x})",
14 result.auth_level, result.attribute
15 );
16
17 device.start_graph_mode(GraphSampleRate::Sps50).await?;
18 tokio::time::sleep(Duration::from_millis(200)).await;
19 let response = device.request_data(AttributeSet::single(Attribute::AdcQueue)).await;
20 device.stop_graph_mode().await?;
21
22 let response = response?;
23 let samples = response.get_adc_queue().map(|queue| queue.samples.len()).unwrap_or(0);
24 println!("AdcQueue samples received after level-2 auth: {samples}");
25
26 Ok(())
27}pub fn from_attributes<I>(attrs: I) -> Selfwhere
I: IntoIterator<Item = Attribute>,
pub fn with(self, attr: Attribute) -> Self
pub fn contains(&self, attr: Attribute) -> bool
Sourcepub fn contains_any<I>(&self, attrs: I) -> boolwhere
I: IntoIterator<Item = Attribute>,
pub fn contains_any<I>(&self, attrs: I) -> boolwhere
I: IntoIterator<Item = Attribute>,
Check if any of the given attributes are present
Sourcepub fn contains_all<I>(&self, attrs: I) -> boolwhere
I: IntoIterator<Item = Attribute>,
pub fn contains_all<I>(&self, attrs: I) -> boolwhere
I: IntoIterator<Item = Attribute>,
Check if all of the given attributes are present
Sourcepub fn iter(&self) -> impl Iterator<Item = Attribute> + '_
pub fn iter(&self) -> impl Iterator<Item = Attribute> + '_
Iterate over all attributes in the set
The wire field is 15 bits wide, so bit 15 is never part of a set.
pub fn to_vec(&self) -> Vec<Attribute>
pub const fn raw(&self) -> u16
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Trait Implementations§
Source§impl Clone for AttributeSet
impl Clone for AttributeSet
impl Copy for AttributeSet
Source§impl Debug for AttributeSet
impl Debug for AttributeSet
impl Eq for AttributeSet
Source§impl From<Attribute> for AttributeSet
impl From<Attribute> for AttributeSet
Source§impl FromIterator<Attribute> for AttributeSet
impl FromIterator<Attribute> for AttributeSet
Source§impl PartialEq for AttributeSet
impl PartialEq for AttributeSet
impl StructuralPartialEq for AttributeSet
Auto Trait Implementations§
impl Freeze for AttributeSet
impl RefUnwindSafe for AttributeSet
impl Send for AttributeSet
impl Sync for AttributeSet
impl Unpin for AttributeSet
impl UnsafeUnpin for AttributeSet
impl UnwindSafe for AttributeSet
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