1use facet::Facet;
2
3#[repr(u8)]
7#[derive(Debug, Clone, PartialEq, Eq, Facet)]
8pub enum MetadataValue<'a> {
9 String(&'a str) = 0,
10 Bytes(&'a [u8]) = 1,
11 U64(u64) = 2,
12}
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Facet)]
21#[repr(transparent)]
22#[facet(transparent)]
23pub struct MetadataFlags(u64);
24
25impl MetadataFlags {
26 pub const NONE: Self = Self(0);
28
29 pub const SENSITIVE: Self = Self(1 << 0);
31
32 pub const NO_PROPAGATE: Self = Self(1 << 1);
34
35 pub fn contains(self, other: Self) -> bool {
37 (self.0 & other.0) == other.0
38 }
39}
40
41impl std::ops::BitOr for MetadataFlags {
42 type Output = Self;
43 fn bitor(self, rhs: Self) -> Self {
44 Self(self.0 | rhs.0)
45 }
46}
47
48impl std::ops::BitOrAssign for MetadataFlags {
49 fn bitor_assign(&mut self, rhs: Self) {
50 self.0 |= rhs.0;
51 }
52}
53
54impl std::ops::BitAnd for MetadataFlags {
55 type Output = Self;
56 fn bitand(self, rhs: Self) -> Self {
57 Self(self.0 & rhs.0)
58 }
59}
60
61impl std::ops::BitAndAssign for MetadataFlags {
62 fn bitand_assign(&mut self, rhs: Self) {
63 self.0 &= rhs.0;
64 }
65}
66
67#[derive(Debug, Clone, PartialEq, Eq, Facet)]
71pub struct MetadataEntry<'a> {
72 pub key: &'a str,
73 pub value: MetadataValue<'a>,
74 pub flags: MetadataFlags,
75}
76
77pub type Metadata<'a> = Vec<MetadataEntry<'a>>;