1use core::fmt;
4
5#[repr(u8)]
8#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
9pub enum StreamType {
10 Control = 0,
12 Audio = 1,
14 Text = 2,
16 Signal = 3,
18}
19
20impl StreamType {
21 pub const fn as_u8(self) -> u8 {
23 self as u8
24 }
25}
26
27impl TryFrom<u32> for StreamType {
28 type Error = u32;
29 fn try_from(v: u32) -> Result<Self, u32> {
30 match v {
31 0 => Ok(Self::Control),
32 1 => Ok(Self::Audio),
33 2 => Ok(Self::Text),
34 3 => Ok(Self::Signal),
35 other => Err(other),
36 }
37 }
38}
39
40impl TryFrom<u8> for StreamType {
41 type Error = u8;
42 fn try_from(v: u8) -> Result<Self, u8> {
43 StreamType::try_from(v as u32).map_err(|_| v)
44 }
45}
46
47impl fmt::Display for StreamType {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 f.write_str(match self {
50 Self::Control => "control",
51 Self::Audio => "audio",
52 Self::Text => "text",
53 Self::Signal => "signal",
54 })
55 }
56}