1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::errors::prelude::*;

/// the order of the bits packed/unpacked
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
pub enum BitOrder {
    /// standard binary representation
    Big,
    /// reversed order
    Little,
}

/// BitOrder trait
pub trait BitOrderType {

    /// Parse input to BitOrder type
    fn to_bit_order(self) -> Result<BitOrder, ArrayError>;
}

impl BitOrderType for BitOrder {

    fn to_bit_order(self) -> Result<BitOrder, ArrayError> {
        Ok(self)
    }
}
impl BitOrderType for &str {

    fn to_bit_order(self) -> Result<BitOrder, ArrayError> {
        match self {
            "big" => Ok(BitOrder::Big),
            "little" => Ok(BitOrder::Little),
            _ => Err(ArrayError::ParameterError { param: "`bit_order`", message: "must be one of {`big`, `little`}" })
        }
    }
}
impl BitOrderType for String {

    fn to_bit_order(self) -> Result<BitOrder, ArrayError> {
        match self.as_str() {
            "big" => Ok(BitOrder::Big),
            "little" => Ok(BitOrder::Little),
            _ => Err(ArrayError::ParameterError { param: "`bit_order`", message: "must be one of {`big`, `little`}" })
        }
    }
}