-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
154 lines (119 loc) · 2.88 KB
/
Copy pathlib.rs
File metadata and controls
154 lines (119 loc) · 2.88 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#![deny(unused_results)]
#![forbid(unsafe_code)]
#![cfg_attr(not(test), no_std)]
// TODO no_panic (crate)
extern crate alloc;
use alloc::boxed::Box;
pub use byte_storage;
use byte_storage::ByteStorage;
num_enum! {
pub enum Tag {
b'U' = Uint,
b'I' = Int,
b'F' = Bool,
b'N' = Uints,
b'B' = Bytes,
b'S' = String,
b'P' = Tuple,
b'L' = List,
// TODO: O&0 distinguish?
b'O' = Option,
b'A' = Alias,
b'E' = Enum,
b'C' = Choice,
b'R' = Struct,
b'T' = Type,
b'D' = TypeId,
// implicit tuple types
b'M' = ListItems,
b'G' = Generics,
} as u8 else reader::Error => Tag
}
// TODO type tag & type id tag as single byte value?
num_enum! {
pub enum TypeTag {
b'0' = Unknown,
b'u' = Uint,
b'i' = Int,
b'f' = Bool,
b'n' = Uints,
b'b' = Bytes,
b's' = String,
b'p' = Tuple,
// TODO: I&l distinguish?
b'l' = List,
b'o' = Option,
b'a' = Alias,
b'e' = Enum,
b'c' = Choice,
b'r' = Struct,
b't' = Type,
b'd' = TypeId,
} as u8 else reader::Error => TypeTag
}
num_enum! {
pub enum TypeIdTag {
b'x' = Anonymous,
b'y' = Std,
// b'z' = ThirdParty,
} as u8 else reader::Error => TypeIdTag
}
type VariantId = u128;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(test, derive(arbitrary::Arbitrary))]
pub enum Type {
Unknown,
Uint,
Int,
Bool,
Uints,
Bytes,
String,
Tuple(Box<[Type]>),
List(Box<Type>),
Option(Box<Type>),
Alias(TypeId, Box<[Type]>),
Enum(TypeId),
Choice(TypeId, Box<[Type]>),
Struct(TypeId, Box<[Type]>),
Type,
TypeId,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(test, derive(arbitrary::Arbitrary))]
pub enum TypeId {
Anonymous,
Std(u128),
// TODO third-party
}
// TODO impl<B1: PartialEq<B2>, B2> PartialEq&PartialOrd<Value<B2>> for Value<B1>
// TODO variant structs?
// TODO no value & matching r&w api
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(test, derive(arbitrary::Arbitrary))]
pub enum Value<B: AsRef<[u8]> + ByteStorage> {
Uint(u128),
Int(i128),
Bool(bool),
Uints(Box<[u128]>),
Bytes(B),
String(Box<[char]>),
Tuple(Box<[Value<B>]>),
List(Type, Box<[Value<B>]>),
Option(Type, Option<Box<Value<B>>>),
Alias(TypeId, Box<[Type]>, Box<Value<B>>),
Enum(TypeId, VariantId),
Choice(TypeId, Box<[Type]>, VariantId, Box<Value<B>>),
Struct(TypeId, Box<[Type]>, Box<[Value<B>]>),
Type(Type),
TypeId(TypeId),
}
mod macros;
pub(crate) mod int;
pub mod casting;
pub mod reader;
pub mod writer;
#[cfg(feature = "text-writer")]
pub mod text_writer;
// #[cfg(test)]
// mod tests;