Skip to content

Commit 26cf9b4

Browse files
committed
add bincode support; tag 0.1.26
1 parent 2ef8938 commit 26cf9b4

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use-serde = ["serde", "serde_json"]
3030
[dependencies]
3131
serde = { version = "1.0.147", optional = true }
3232
serde_json = { version = "1.0.87", optional = true }
33+
bincode = "2.0.0-rc.3"
3334

3435
[dev-dependencies]
3536
criterion = "0.4.0"

examples/bincode.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use cirru_parser::{format, parse, Cirru, CirruWriterOptions};
2+
use std::fs;
3+
4+
fn main() -> Result<(), String> {
5+
let large_demo = "/Users/chenyong/repo/calcit-lang/editor/compact.cirru";
6+
let content = fs::read_to_string(large_demo).unwrap();
7+
8+
let v = parse(&content)?;
9+
10+
let buf = bincode::encode_to_vec(&v, bincode::config::standard()).map_err(|e| e.to_string())?;
11+
12+
let bin_out = "target/bincode/calcit-info.bin";
13+
14+
fs::write(bin_out, &buf).map_err(|e| e.to_string())?;
15+
16+
let (decoded, _length): (Vec<Cirru>, usize) = bincode::decode_from_slice(&buf[..], bincode::config::standard()).unwrap();
17+
18+
let writer_options = CirruWriterOptions { use_inline: true };
19+
println!("wrote to {}", bin_out);
20+
21+
println!("{}", format(&decoded, writer_options).unwrap());
22+
23+
Ok(())
24+
}

src/primes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use bincode::{Decode, Encode};
12
use std::clone::Clone;
23
use std::fmt;
34
use std::hash::Hash;
@@ -14,7 +15,7 @@ use serde::{
1415
use crate::s_expr;
1516

1617
/// Cirru uses nested Vecters and Strings as data structure
17-
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18+
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Decode, Encode)]
1819
pub enum Cirru {
1920
Leaf(Box<str>),
2021
List(Vec<Cirru>),

0 commit comments

Comments
 (0)