diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index f5296de..c04a216 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -12,24 +12,24 @@ jobs: name: Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: - # toolchain: nightly + toolchain: nightly components: clippy - uses: supplypike/setup-bin@v3 with: - uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.0-a3/cr" + uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.21/cr" name: "cr" - version: "0.8.0-a3" + version: "0.8.21" - uses: supplypike/setup-bin@v3 with: - uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.0-a3/caps" + uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.21/caps" name: "caps" - version: "0.8.0-a3" + version: "0.8.21" - run: cargo build --release diff --git a/Cargo.lock b/Cargo.lock index b2907aa..4bb1dd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,25 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bincode" +version = "2.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95" +dependencies = [ + "bincode_derive", + "serde", +] + +[[package]] +name = "bincode_derive" +version = "2.0.0-rc.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c" +dependencies = [ + "virtue", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -37,7 +56,7 @@ checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "calcit_std" -version = "0.2.0-a1" +version = "0.2.1" dependencies = [ "chrono", "cirru_edn", @@ -81,10 +100,11 @@ dependencies = [ [[package]] name = "cirru_edn" -version = "0.4.2" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5399b8563cb708471e8ded7433bc65e725fa17e38eb339de468445c1f3ee3c70" +checksum = "8fedb67d87075cec51cc76323ebceb2e177c157ab06b4111e37849e5e15f5db7" dependencies = [ + "bincode", "cirru_parser", "hex", "lazy_static", @@ -92,9 +112,12 @@ dependencies = [ [[package]] name = "cirru_parser" -version = "0.1.25" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1297388204c9d3c72d1cafea80682fd6384e79c66dfe980460886bff7387e684" +checksum = "7ad2d076b9a6dde2b253341ed2d8752949d8ab3ade476157c859647df6c82eaf" +dependencies = [ + "bincode", +] [[package]] name = "codespan-reporting" @@ -466,6 +489,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "virtue" +version = "0.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314" + [[package]] name = "walkdir" version = "2.3.3" diff --git a/Cargo.toml b/Cargo.toml index 4073d8c..dc45d26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcit_std" -version = "0.2.0-a1" +version = "0.2.1" authors = ["jiyinyiyong "] edition = "2021" @@ -17,8 +17,8 @@ crate-type = ["dylib"] # Creates dynamic lib serde = { version = "1.0.185", features = ["derive"] } serde_json = "1.0.105" chrono = "0.4.26" -cirru_edn = "0.4.2" -cirru_parser = "0.1.25" +cirru_edn = "0.5.4" +cirru_parser = "0.1.28" nanoid = "0.4.0" rand = "0.8.5" ctrlc = "3.4.0" diff --git a/calcit.cirru b/calcit.cirru index 994b0d7..ac82e31 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -1,6 +1,6 @@ {} (:package |calcit.std) - :configs $ {} (:init-fn |calcit.std.test/main!) (:port 6001) (:reload-fn |calcit.std.test/reload!) (:version |0.2.0-a2) + :configs $ {} (:init-fn |calcit.std.test/main!) (:port 6001) (:reload-fn |calcit.std.test/reload!) (:version |0.2.1) :modules $ [] :entries $ {} :files $ {} diff --git a/compact.cirru b/compact.cirru index 45601c7..abd9cbf 100644 --- a/compact.cirru +++ b/compact.cirru @@ -1,6 +1,6 @@ {} (:package |calcit.std) - :configs $ {} (:init-fn |calcit.std.test/main!) (:reload-fn |calcit.std.test/reload!) (:version |0.2.0-a2) + :configs $ {} (:init-fn |calcit.std.test/main!) (:reload-fn |calcit.std.test/reload!) (:version |0.2.1) :modules $ [] :entries $ {} :files $ {} diff --git a/src/date.rs b/src/date.rs index 82e885d..88b4726 100644 --- a/src/date.rs +++ b/src/date.rs @@ -1,7 +1,7 @@ //! TODO, need to store offset as well, //! currently lack of offset, prefer using Local time -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; use chrono::{DateTime, Datelike, Duration, Local, LocalResult, NaiveDate, TimeZone, Timelike, Utc, Weekday}; use cirru_edn::Edn; @@ -49,12 +49,12 @@ pub fn format_time(args: Vec) -> Result { if args.len() == 2 { match (&args[0], &args[1]) { (Edn::Number(n), Edn::Nil) => match Local.timestamp_opt((n.floor() / 1000.0) as i64, (n.fract() * 1_000_000.0) as u32) { - LocalResult::Single(time) => Ok(Edn::Str(time.to_rfc3339().into_boxed_str())), + LocalResult::Single(time) => Ok(Edn::Str(time.to_rfc3339().into())), LocalResult::Ambiguous(min_time, max_time) => Err(format!("format-time failed, ambiguous: {min_time} {max_time}")), LocalResult::None => Err(format!("format-time out of range: {n}")), }, (Edn::Number(n), Edn::Str(f)) => match Local.timestamp_opt((n.floor() / 1000.0) as i64, (n.fract() * 1_000_000.0) as u32) { - LocalResult::Single(time) => Ok(Edn::Str(time.format(f).to_string().into_boxed_str())), + LocalResult::Single(time) => Ok(Edn::Str(time.format(f).to_string().into())), LocalResult::None => Err(format!("format-time out of range: {n} {f}")), LocalResult::Ambiguous(min_time, max_time) => Err(format!("format-time ambiguous: {min_time} {max_time}")), }, @@ -114,13 +114,13 @@ pub fn from_ymd(args: Vec) -> Result { .and_hms_opt(0, 0, 0) .ok_or("from_ymd got none")?, ) { - LocalResult::None => Ok(Edn::Tuple(Box::new(Edn::tag("none")), vec![])), + LocalResult::None => Ok(Edn::Tuple(Arc::new(Edn::tag("none")), vec![])), LocalResult::Single(d) => Ok(Edn::Tuple( - Box::new(Edn::tag("single")), + Arc::new(Edn::tag("single")), vec![Edn::Number(d.timestamp_millis() as f64)], )), LocalResult::Ambiguous(d, d2) => Ok(Edn::Tuple( - Box::new(Edn::tag("ambiguous")), + Arc::new(Edn::tag("ambiguous")), vec![Edn::Number(d.timestamp_millis() as f64), Edn::Number(d2.timestamp_millis() as f64)], )), } @@ -148,20 +148,20 @@ pub fn from_ywd(args: Vec) -> Result { 6 => Weekday::Sat, _ => { return Ok(Edn::Tuple( - Box::new(Edn::tag("err")), + Arc::new(Edn::tag("err")), vec![Edn::str(format!("invalid digit for weekday: {d}"))], )) } }; match NaiveDate::from_isoywd_opt(*y as i32, *w as u32, weekday) { Some(time) => match Local.from_local_datetime(&time.and_hms_opt(0, 0, 0).ok_or("hms got none")?) { - LocalResult::None => Ok(Edn::Tuple(Box::new(Edn::tag("none")), vec![])), + LocalResult::None => Ok(Edn::Tuple(Arc::new(Edn::tag("none")), vec![])), LocalResult::Single(d) => Ok(Edn::Tuple( - Box::new(Edn::tag("single")), + Arc::new(Edn::tag("single")), vec![Edn::Number(d.timestamp_millis() as f64)], )), LocalResult::Ambiguous(d, d2) => Ok(Edn::Tuple( - Box::new(Edn::tag("single")), + Arc::new(Edn::tag("single")), vec![Edn::Number(d.timestamp_millis() as f64), Edn::Number(d2.timestamp_millis() as f64)], )), }, diff --git a/src/fs.rs b/src/fs.rs index a6d1ad9..910eaa7 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -15,7 +15,7 @@ pub fn read_file(args: Vec) -> Result { if let Edn::Str(name) = &args[0] { let task = fs::read_to_string(&**name); match task { - Ok(s) => Ok(Edn::Str(s.into_boxed_str())), + Ok(s) => Ok(Edn::Str(s.into())), Err(e) => Err(format!("Failed to read file {name:?}: {e}")), } } else { @@ -129,7 +129,7 @@ pub fn read_dir(args: Vec) -> Result { Ok(children) => { let mut content: Vec = vec![]; for c in children { - content.push(Edn::Str(format!("{}", c.unwrap().path().display()).into_boxed_str())); + content.push(Edn::Str(format!("{}", c.unwrap().path().display()).into())); } // println!("child dir: {:?}", content); @@ -245,7 +245,7 @@ pub fn walk_dir(args: Vec) -> Result { let entry = entry.unwrap(); let path = entry.path(); if path.is_file() { - content.push(Edn::Str(format!("{}", path.display()).into_boxed_str())); + content.push(Edn::Str(format!("{}", path.display()).into())); } } Ok(Edn::List(content)) @@ -267,7 +267,7 @@ pub fn glob_call(args: Vec) -> Result { match entry { Ok(entry) => { if entry.is_file() { - content.push(Edn::Str(format!("{}", entry.display()).into_boxed_str())); + content.push(Edn::Str(format!("{}", entry.display()).into())); } } Err(e) => return Err(format!("Failed to read: {}", e)), diff --git a/src/hash.rs b/src/hash.rs index d2b6566..cad7b99 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -4,9 +4,7 @@ use cirru_edn::Edn; pub fn md5(args: Vec) -> Result { if args.len() == 1 { if let Edn::Str(s) = &args[0] { - Ok(Edn::Str( - format!("{:x}", md5::compute(&**s)).into_boxed_str(), - )) + Ok(Edn::Str(format!("{:x}", md5::compute(&**s)).into())) } else { Err(format!("md5 expected a string, {}", &args[0])) } diff --git a/src/json.rs b/src/json.rs index 3dd9b69..9b9de3a 100644 --- a/src/json.rs +++ b/src/json.rs @@ -14,7 +14,7 @@ pub fn json_to_edn(data: &Value) -> Edn { // special logic to parse keyword Edn::Tag(EdnTag::new(s.strip_prefix(':').unwrap())) } else { - Edn::Str(s.to_owned().into_boxed_str()) + Edn::Str(s.to_owned().into()) } } Value::Array(xs) => { @@ -30,7 +30,7 @@ pub fn json_to_edn(data: &Value) -> Edn { let key = if k.starts_with(':') { Edn::tag(k.strip_prefix(':').unwrap()) } else { - Edn::Str(k.to_owned().into_boxed_str()) + Edn::Str(k.to_owned().into()) }; ys.insert(key, json_to_edn(v)); } @@ -118,14 +118,14 @@ pub fn stringify_json(args: Vec) -> Result { Edn::Bool(add_colon) => { let ret = edn_to_json(args[0].to_owned(), *add_colon)?; match serde_json::to_string(&ret) { - Ok(s) => Ok(Edn::Str(s.into_boxed_str())), + Ok(s) => Ok(Edn::Str(s.into())), Err(e) => Err(format!("failed to generate string: {e}")), } } Edn::Nil => { let ret = edn_to_json(args[0].to_owned(), false)?; match serde_json::to_string(&ret) { - Ok(s) => Ok(Edn::Str(s.into_boxed_str())), + Ok(s) => Ok(Edn::Str(s.into())), Err(e) => Err(format!("failed to generate string: {e}")), } } diff --git a/src/lib.rs b/src/lib.rs index ed78998..8d79150 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,5 +20,5 @@ pub use time::{set_interval, set_timeout}; #[no_mangle] pub fn abi_version() -> String { - String::from("0.0.6") + String::from("0.0.7") } diff --git a/src/process.rs b/src/process.rs index ea41308..8bec53e 100644 --- a/src/process.rs +++ b/src/process.rs @@ -17,10 +17,7 @@ pub fn execute_command(args: Vec) -> Result { xs.push((**s).to_owned()); } } else { - return Err(format!( - "execute-command expected string in list, got {}", - piece - )); + return Err(format!("execute-command expected string in list, got {}", piece)); } } @@ -28,18 +25,12 @@ pub fn execute_command(args: Vec) -> Result { Ok(t) => { let content = String::from_utf8(t.stdout).unwrap(); let stderr = String::from_utf8(t.stderr).unwrap(); - Ok(Edn::List(vec![ - Edn::Str(content.into_boxed_str()), - Edn::Str(stderr.into_boxed_str()), - ])) + Ok(Edn::List(vec![Edn::Str(content.into()), Edn::Str(stderr.into())])) } Err(e) => Err(format!("Failed to excute: {e}")), } } - (_, _) => Err(format!( - "excute-command expected string and list: {:?}", - args - )), + (_, _) => Err(format!("excute-command expected string and list: {:?}", args)), } } else { Err(format!("excute-command expected 2 args: {args:?}")) diff --git a/src/random.rs b/src/random.rs index 3fb546e..6e5e0e3 100644 --- a/src/random.rs +++ b/src/random.rs @@ -69,19 +69,16 @@ pub fn call_nanoid(xs: Vec) -> Result { }; match (size, &xs[1]) { - (None, Edn::Nil) => Ok(Edn::Str(nanoid!().into_boxed_str())), - (Some(n), Edn::Nil) => Ok(Edn::Str(nanoid!(n).into_boxed_str())), + (None, Edn::Nil) => Ok(Edn::Str(nanoid!().into())), + (Some(n), Edn::Nil) => Ok(Edn::Str(nanoid!(n).into())), (Some(n), Edn::Str(s)) => { let mut charset: Vec = vec![]; for c in s.chars() { charset.push(c); } - Ok(Edn::Str(nanoid!(n, &charset).into_boxed_str())) + Ok(Edn::Str(nanoid!(n, &charset).into())) } - (a, b) => Err(format!( - "nanoid! expected size or charset, got: {:?} {:?}", - a, b - )), + (a, b) => Err(format!("nanoid! expected size or charset, got: {:?} {:?}", a, b)), } } else { Err(format!("nanoid! expected 2 args, got: {xs:?}"))