arch_pkg_text/value/
skip_or_array.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3pub enum SkipOrArray<const LEN: usize> {
4 Skip,
6 Array([u8; LEN]),
8}
9
10impl<const LEN: usize> SkipOrArray<LEN> {
11 #[must_use]
13 pub fn is_skip(&self) -> bool {
14 matches!(self, Self::Skip)
15 }
16
17 #[must_use]
19 pub fn is_array(&self) -> bool {
20 matches!(self, Self::Array(_))
21 }
22
23 pub fn try_into_array(self) -> Option<[u8; LEN]> {
25 match self {
26 SkipOrArray::Array(array) => Some(array),
27 SkipOrArray::Skip => None,
28 }
29 }
30
31 pub fn as_array(&self) -> Option<&[u8; LEN]> {
33 match self {
34 SkipOrArray::Array(array) => Some(array),
35 SkipOrArray::Skip => None,
36 }
37 }
38
39 pub fn as_slice(&self) -> Option<&[u8]> {
41 self.as_array().map(|x| x.as_slice())
42 }
43}
44
45impl<const LEN: usize> TryFrom<SkipOrArray<LEN>> for [u8; LEN] {
46 type Error = ();
47 fn try_from(value: SkipOrArray<LEN>) -> Result<Self, Self::Error> {
48 value.try_into_array().ok_or(())
49 }
50}