-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.rs
More file actions
70 lines (52 loc) · 1.5 KB
/
Copy pathencode.rs
File metadata and controls
70 lines (52 loc) · 1.5 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
#[cfg(any(feature = "std", feature = "serde"))]
use serde::{Deserialize, Serialize};
#[cfg(feature = "std")]
fn main_std() {
use nson::id::Id;
use nson::{decode, encode};
let id = Id::new();
println!("{:?}", id);
println!("{:?}", id.timestamp());
println!("{:?}", id.bytes());
let a = A { b: B(123) };
let ret = encode::to_nson(&a);
println!("{:?}", ret);
let ret = decode::from_nson::<A>(ret.unwrap());
println!("{:?}", ret);
let m = nson::m! {"a": [123i32, 456f32], "b": "hello"};
println!("{:?}", m);
println!("{}", m);
println!("{}", u8::MAX);
}
#[cfg(all(feature = "alloc", feature = "serde"))]
fn main_nostd() {
use nson::Id;
use nson::{decode, encode};
let id = Id::new_raw(123, 45, 678);
println!("{:?}", id);
println!("{:?}", id.timestamp());
println!("{:?}", id.bytes());
let a = A { b: B(123) };
let ret = encode::to_nson(&a);
println!("{:?}", ret);
let ret = decode::from_nson::<A>(ret.unwrap());
println!("{:?}", ret);
let m = nson::m! {"a": [123i32, 456f32], "b": "hello"};
println!("{:?}", m);
println!("{}", m);
println!("{}", u8::MAX);
}
fn main() {
#[cfg(feature = "std")]
main_std();
#[cfg(all(feature = "alloc", feature = "serde"))]
main_nostd();
}
#[cfg(any(feature = "std", feature = "serde"))]
#[derive(Serialize, Deserialize, Debug)]
struct A {
b: B,
}
#[cfg(any(feature = "std", feature = "serde"))]
#[derive(Serialize, Deserialize, Debug)]
struct B(u64);