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
45
46
47
48
49
50
51
52
53
54
55
56
use crate::bigint::private;
pub const BINARY_LEN: usize = 384;
pub const BINARY_LEN_IN_U8: usize = BINARY_LEN / 8;
pub const BINARY_LEN_IN_U32: usize = BINARY_LEN / 32;
pub type U8Repr = [u8; BINARY_LEN_IN_U8];
pub type U32Repr = [u32; BINARY_LEN_IN_U32];
#[derive(Clone, Copy, Debug)]
pub struct BigEndian {}
#[derive(Clone, Copy, Debug)]
pub struct LittleEndian {}
trait EndianType: private::Sealed {}
impl EndianType for BigEndian {}
impl EndianType for LittleEndian {}
pub trait BinaryRepresentation: private::Sealed + Clone {
type T;
fn iter(&self) -> std::slice::Iter<'_, Self::T>;
}
impl private::Sealed for U8Repr {}
impl private::Sealed for U32Repr {}
impl BinaryRepresentation for U8Repr {
type T = u8;
fn iter(&self) -> std::slice::Iter<'_, Self::T> {
(self as &[u8]).iter()
}
}
impl BinaryRepresentation for U32Repr {
type T = u32;
fn iter(&self) -> std::slice::Iter<'_, Self::T> {
(self as &[u32]).iter()
}
}
#[derive(Clone, Debug)]
pub enum Error {
BinaryExceedsTernaryRange,
TernaryExceedsBinaryRange,
}