1use crate::*;
2
3#[derive(Copy, Clone)]
7pub struct UnionSelector(u8);
8
9impl From<UnionSelector> for u8 {
10 fn from(union_selector: UnionSelector) -> u8 {
11 union_selector.0
12 }
13}
14
15impl PartialEq<u8> for UnionSelector {
16 fn eq(&self, other: &u8) -> bool {
17 self.0 == *other
18 }
19}
20
21impl UnionSelector {
22 pub fn new(selector: u8) -> Result<Self, DecodeError> {
24 Some(selector)
25 .filter(|_| selector <= MAX_UNION_SELECTOR)
26 .map(Self)
27 .ok_or(DecodeError::UnionSelectorInvalid(selector))
28 }
29}