arr_rs/numeric/types/
binary.rs1use crate::errors::prelude::*;
2
3#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
5pub enum BitOrder {
6 Big,
8 Little,
10}
11
12pub trait BitOrderType {
14
15 fn to_bit_order(self) -> Result<BitOrder, ArrayError>;
21}
22
23impl BitOrderType for BitOrder {
24
25 fn to_bit_order(self) -> Result<BitOrder, ArrayError> {
26 Ok(self)
27 }
28}
29
30impl BitOrderType for &str {
31
32 fn to_bit_order(self) -> Result<BitOrder, ArrayError> {
33 match self {
34 "big" => Ok(BitOrder::Big),
35 "little" => Ok(BitOrder::Little),
36 _ => Err(ArrayError::ParameterError { param: "`bit_order`", message: "must be one of {`big`, `little`}" })
37 }
38 }
39}
40
41impl BitOrderType for String {
42
43 fn to_bit_order(self) -> Result<BitOrder, ArrayError> {
44 match self.as_str() {
45 "big" => Ok(BitOrder::Big),
46 "little" => Ok(BitOrder::Little),
47 _ => Err(ArrayError::ParameterError { param: "`bit_order`", message: "must be one of {`big`, `little`}" })
48 }
49 }
50}