toad_msg/msg/opt/known/
content_format.rs1#[non_exhaustive]
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4pub enum ContentFormat {
5 Text,
7 LinkFormat,
9 Xml,
11 OctetStream,
13 Exi,
15 Json,
17 Other(u16),
19}
20
21impl ContentFormat {
22 pub fn bytes(&self) -> [u8; 2] {
24 u16::from(self).to_be_bytes()
25 }
26}
27
28impl<'a> From<&'a ContentFormat> for u16 {
29 fn from(f: &'a ContentFormat) -> Self {
30 use ContentFormat::*;
31 match *f {
32 | Text => 0,
33 | LinkFormat => 40,
34 | Xml => 41,
35 | OctetStream => 42,
36 | Exi => 47,
37 | Json => 50,
38 | Other(n) => n,
39 }
40 }
41}
42
43impl From<u16> for ContentFormat {
44 fn from(n: u16) -> Self {
45 use ContentFormat::*;
46 match n {
47 | 0 => Text,
48 | 40 => LinkFormat,
49 | 41 => Xml,
50 | 42 => OctetStream,
51 | 47 => Exi,
52 | 50 => Json,
53 | n => Other(n),
54 }
55 }
56}
57
58impl<'a> IntoIterator for &'a ContentFormat {
59 type Item = u8;
60
61 type IntoIter = <[u8; 2] as IntoIterator>::IntoIter;
62
63 fn into_iter(self) -> Self::IntoIter {
64 self.bytes().into_iter()
65 }
66}