embassy_usb/
types.rs

1//! USB types.
2
3/// A handle for a USB interface that contains its number.
4#[derive(Debug, Copy, Clone, Eq, PartialEq)]
5#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6#[repr(transparent)]
7pub struct InterfaceNumber(pub u8);
8
9impl InterfaceNumber {
10    pub(crate) const fn new(index: u8) -> InterfaceNumber {
11        InterfaceNumber(index)
12    }
13}
14
15impl From<InterfaceNumber> for u8 {
16    fn from(n: InterfaceNumber) -> u8 {
17        n.0
18    }
19}
20
21impl core::fmt::Display for InterfaceNumber {
22    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
23        write!(f, "{}", self.0)
24    }
25}
26
27/// A handle for a USB string descriptor that contains its index.
28#[derive(Copy, Clone, Eq, PartialEq)]
29#[cfg_attr(feature = "defmt", derive(defmt::Format))]
30#[repr(transparent)]
31pub struct StringIndex(pub u8);
32
33impl StringIndex {
34    pub(crate) const fn new(index: u8) -> StringIndex {
35        StringIndex(index)
36    }
37}
38
39impl From<StringIndex> for u8 {
40    fn from(i: StringIndex) -> u8 {
41        i.0
42    }
43}