diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 447d5f6..8b1befe 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -12,19 +12,11 @@ jobs: name: Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: supplypike/setup-bin@v3 + - uses: calcit-lang/setup-cr@0.0.3 with: - uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.0/cr" - name: "cr" - version: "0.8.0" - - - uses: supplypike/setup-bin@v3 - with: - uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.0/caps" - name: "caps" - version: "0.8.0" + version: "0.8.52" - uses: dtolnay/rust-toolchain@stable with: diff --git a/Cargo.lock b/Cargo.lock index a380c73..8d837de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,25 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +[[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" @@ -34,7 +53,7 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "calcit_http" -version = "0.0.5" +version = "0.0.8" dependencies = [ "cirru_edn", "cirru_parser", @@ -55,10 +74,11 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cirru_edn" -version = "0.5.0" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a35d38ee59f7409023f9dee361dc98760f33c9ad1f21283e536939d9561ed44" +checksum = "b4aa8a3c939e1480883ea1371deab36c179e621779f9a7731554b9bec3840189" dependencies = [ + "bincode", "cirru_parser", "hex", "lazy_static", @@ -66,9 +86,12 @@ dependencies = [ [[package]] name = "cirru_parser" -version = "0.1.25" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1297388204c9d3c72d1cafea80682fd6384e79c66dfe980460886bff7387e684" +checksum = "c96247e15778d471f8c94b321fa11220dfb987546fcf8fb73b1a5c2b3a018a78" +dependencies = [ + "bincode", +] [[package]] name = "core-foundation" @@ -840,6 +863,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "virtue" +version = "0.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314" + [[package]] name = "want" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 4719e60..9e8e653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcit_http" -version = "0.0.5" +version = "0.0.8" authors = ["jiyinyiyong "] edition = "2021" @@ -13,6 +13,6 @@ crate-type = ["dylib"] # Creates dynamic lib # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cirru_edn = "0.5.0" -cirru_parser = "0.1.25" +cirru_edn = "0.6.8" +cirru_parser = "0.1.29" reqwest = { version = "0.11.20", features = ["blocking"] } diff --git a/calcit.cirru b/calcit.cirru index 424dcae..62cd1a1 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -1,6 +1,6 @@ {} (:package |fetch) - :configs $ {} (:init-fn |fetch.test/main!) (:port 6001) (:reload-fn |fetch.test/reload!) (:version |0.0.5) + :configs $ {} (:init-fn |fetch.test/main!) (:port 6001) (:reload-fn |fetch.test/reload!) (:version |0.0.8) :modules $ [] :entries $ {} :files $ {} diff --git a/compact.cirru b/compact.cirru index 988744d..df54c9f 100644 --- a/compact.cirru +++ b/compact.cirru @@ -1,6 +1,6 @@ {} (:package |fetch) - :configs $ {} (:init-fn |fetch.test/main!) (:reload-fn |fetch.test/reload!) (:version |0.0.5) + :configs $ {} (:init-fn |fetch.test/main!) (:reload-fn |fetch.test/reload!) (:version |0.0.8) :modules $ [] :entries $ {} :files $ {} diff --git a/src/lib.rs b/src/lib.rs index 0477dea..e2ec326 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use cirru_edn::Edn; +use cirru_edn::{Edn, EdnTupleView}; use reqwest::{ header::{HeaderMap, HeaderName, HeaderValue}, Method, @@ -7,10 +7,16 @@ use std::sync::Arc; use std::thread::spawn; pub fn wrap_ok(x: Edn) -> Edn { - Edn::Tuple(Box::new(Edn::tag("ok")), vec![x]) + Edn::Tuple(EdnTupleView { + tag: Arc::new(Edn::tag("ok")), + extra: vec![x], + }) } pub fn wrap_err(x: Edn) -> Edn { - Edn::Tuple(Box::new(Edn::tag("err")), vec![x]) + Edn::Tuple(EdnTupleView { + tag: Arc::new(Edn::tag("err")), + extra: vec![x], + }) } struct RequestSkeleton { @@ -22,7 +28,7 @@ struct RequestSkeleton { #[no_mangle] pub fn abi_version() -> String { - String::from("0.0.6") + String::from("0.0.9") } #[no_mangle] @@ -47,11 +53,11 @@ pub fn fetch( a => return Err(format!("unexpected method: {}", a)), }; - let b = builder.body(options.body).headers(options.headers).query(&options.query); + let b = builder.body(options.body).headers(options.headers).query(&*options.query); let ret = match b.send() { Ok(res) => match res.text() { - Ok(s) => handler(vec![wrap_ok(Edn::Str(s.to_string().into_boxed_str()))]), + Ok(s) => handler(vec![wrap_ok(Edn::Str(s.into()))]), Err(e) => handler(vec![wrap_err(Edn::str(format!("failed to turn body into text: {}", e)))]), }, Err(e) => return Err(format!("fetch failed: {}", e)), @@ -80,7 +86,7 @@ fn parse_request_options(info: &Edn) -> Result { match info { Edn::Map(m) => { req.method = match m.get(&Edn::tag("method")) { - Some(Edn::Tag(k)) => k.to_str().parse::().map_err(|x| x.to_string())?, + Some(Edn::Tag(k)) => k.ref_str().parse::().map_err(|x| x.to_string())?, None => Method::GET, Some(a) => return Err(format!("invalid method name: {}", a)), }; @@ -91,7 +97,7 @@ fn parse_request_options(info: &Edn) -> Result { }; match m.get(&Edn::tag("headers")) { Some(Edn::Map(xs)) => { - for (k, v) in xs { + for (k, v) in &xs.0 { match (k, v) { (Edn::Str(k2), Edn::Str(v2)) => { req @@ -101,7 +107,7 @@ fn parse_request_options(info: &Edn) -> Result { (Edn::Tag(k2), Edn::Str(v2)) => { req .headers - .insert(k2.to_str().parse::().unwrap(), v2.parse::().unwrap()); + .insert(k2.ref_str().parse::().unwrap(), v2.parse::().unwrap()); } _ => return Err(format!("expected strings for headers: {}, {}", k, v)), } @@ -118,14 +124,14 @@ fn parse_request_options(info: &Edn) -> Result { for x in xs { if let Edn::List(ys) = x { if ys.len() == 2 { - match (&ys[0], &ys[1]) { + match (&ys.0[0], &ys.0[1]) { (Edn::Str(k), Edn::Str(v)) => { - req.query.push((k.to_owned(), v.to_owned())); + req.query.push((Box::from(&**k), Box::from(&**v))); // quit jump to next call continue; } (Edn::Tag(k), Edn::Str(v)) => { - req.query.push((k.to_str().to_owned(), v.to_owned())); + req.query.push((k.ref_str().into(), Box::from(&**v))); // quit jump to next call continue; }