From 33ee4dc45e8340fddb43b1db1f70d8e057b5ce15 Mon Sep 17 00:00:00 2001 From: jiyinyiyong Date: Wed, 20 Oct 2021 16:21:45 +0800 Subject: [PATCH 1/2] an early demo of requesting --- Cargo.lock | 942 ++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + README.md | 3 +- calcit.cirru | 179 +++++++--- compact.cirru | 40 ++- src/lib.rs | 17 +- 6 files changed, 1102 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 163c92e..8d978ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,14 +2,57 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bumpalo" +version = "3.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + [[package]] name = "calcit_std" version = "0.0.3" dependencies = [ "cirru_edn", "cirru_parser", + "reqwest", ] +[[package]] +name = "cc" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "cirru_edn" version = "0.1.12" @@ -24,3 +67,902 @@ name = "cirru_parser" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b2077243ccce07d54a032dfeb09e68c91d17f87645c501b619ab45a2844cca3" + +[[package]] +name = "core-foundation" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "encoding_rs" +version = "0.8.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a74ea89a0a1b98f6332de42c95baff457ada66d1cb4030f9ff151b2041a1c746" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" + +[[package]] +name = "futures-io" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" + +[[package]] +name = "futures-sink" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" + +[[package]] +name = "futures-task" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" + +[[package]] +name = "futures-util" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +dependencies = [ + "autocfg", + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "h2" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" + +[[package]] +name = "httpdate" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" + +[[package]] +name = "hyper" +version = "0.14.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" + +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + +[[package]] +name = "js-sys" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2f96d100e1cf1929e7719b7edb3b90ab5298072638fccd77be9ce942ecdfce" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mio" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "native-tls" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + +[[package]] +name = "openssl" +version = "0.10.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" + +[[package]] +name = "openssl-sys" +version = "0.9.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" + +[[package]] +name = "ppv-lite86" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ca011bd0129ff4ae15cd04c4eef202cadf6c51c21e47aba319b4e0501db741" + +[[package]] +name = "proc-macro2" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d2927ca2f685faf0fc620ac4834690d29e7abb153add10f5812eef20b5e280" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + +[[package]] +name = "security-framework" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" + +[[package]] +name = "serde_json" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "socket2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "tinyvec" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "winapi", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-bidi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" + +[[package]] +name = "web-sys" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi", +] diff --git a/Cargo.toml b/Cargo.toml index 90b0c1e..487980c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ crate-type = ["dylib"] # Creates dynamic lib [dependencies] cirru_edn = "0.1.12" cirru_parser = "0.1.8" +reqwest = { version = "0.11", features = ["blocking"] } diff --git a/README.md b/README.md index eed6e26..cf51202 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ APIs: ```cirru -lib.core/path-exists? a +fetch.core/fetch |http://calcit-lang.org nil $ fn (text) + println text ``` Install to `~/.config/calcit/modules/`, compile and provide `*.{dylib,so}` file with `./build.sh`. diff --git a/calcit.cirru b/calcit.cirru index d533702..8cf2b90 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -1,47 +1,38 @@ {} - :configs $ {} (:reload-fn |lib.test/reload!) (:port 6001) (:version |0.0.3) + :configs $ {} (:reload-fn |fetch.test/reload!) (:port 6001) (:version |0.0.3) :modules $ [] - :init-fn |lib.test/main! - :ir $ {} (:package |lib) + :init-fn |fetch.test/main! + :ir $ {} (:package |fetch) :files $ {} - |lib.core $ {} + |fetch.core $ {} :defs $ {} - |path-exists? $ {} + |fetch $ {} :data $ {} |T $ {} (:text |defn) (:type :leaf) (:at 1630219258753) (:by |u0) - |j $ {} (:text |path-exists?) (:type :leaf) (:at 1630219258753) (:by |u0) + |j $ {} (:text |fetch) (:type :leaf) (:at 1634715839239) (:by |u0) |r $ {} :data $ {} - |T $ {} (:text |name) (:type :leaf) (:at 1630219268038) (:by |u0) + |T $ {} (:text |url) (:type :leaf) (:at 1634715850457) (:by |u0) + |j $ {} (:text |options) (:type :leaf) (:at 1634715851485) (:by |u0) + |r $ {} (:text |cb) (:type :leaf) (:at 1634716176877) (:by |u0) :type :expr :at 1630219268038 :by |u0 |v $ {} :data $ {} - |T $ {} (:text |&call-dylib-edn) (:type :leaf) (:at 1633253263271) (:by |u0) - |j $ {} + |T $ {} (:text |&callback-dylib-edn) (:type :leaf) (:at 1634716160451) (:by |u0) + |b $ {} :data $ {} - |T $ {} (:text |str) (:type :leaf) (:at 1630219268038) (:by |u0) - |j $ {} - :data $ {} - |D $ {} (:text |or-current-path) (:type :leaf) (:at 1630245627140) (:by |u0) - |T $ {} (:text |calcit-dirname) (:type :leaf) (:at 1630219268038) (:by |u0) - :type :expr - :at 1630245626564 - :by |u0 - |r $ {} (:text "|\"/dylibs/libcalcit_std") (:type :leaf) (:at 1630231388580) (:by |u0) - |v $ {} - :data $ {} - |T $ {} (:text |get-dylib-ext) (:type :leaf) (:at 1630231396884) (:by |u0) - :type :expr - :at 1630231389815 - :by |u0 + |T $ {} (:text |get-dylib-path) (:type :leaf) (:at 1634715951430) (:by |u0) + |j $ {} (:text "|\"/dylibs/libcalcit_std") (:type :leaf) (:at 1634715953339) (:by |u0) :type :expr - :at 1630219268038 + :at 1634715951073 :by |u0 - |r $ {} (:text "|\"path_exists") (:type :leaf) (:at 1630219282714) (:by |u0) - |v $ {} (:text |name) (:type :leaf) (:at 1630219268038) (:by |u0) + |r $ {} (:text "|\"fetch") (:type :leaf) (:at 1634715842381) (:by |u0) + |v $ {} (:text |url) (:type :leaf) (:at 1634715848679) (:by |u0) + |x $ {} (:text |options) (:type :leaf) (:at 1634716174355) (:by |u0) + |y $ {} (:text |cb) (:type :leaf) (:at 1634716179983) (:by |u0) :type :expr :at 1630219268038 :by |u0 @@ -57,13 +48,13 @@ :ns $ {} :data $ {} |T $ {} (:text |ns) (:type :leaf) (:at 1630171366222) (:by |u0) - |j $ {} (:text |lib.core) (:type :leaf) (:at 1630171366222) (:by |u0) + |j $ {} (:text |fetch.core) (:type :leaf) (:at 1630171366222) (:by |u0) |r $ {} :data $ {} |T $ {} (:text |:require) (:type :leaf) (:at 1630175119637) (:by |u0) |j $ {} :data $ {} - |T $ {} (:text |lib.$meta) (:type :leaf) (:at 1634703660055) (:by |u0) + |T $ {} (:text |fetch.$meta) (:type :leaf) (:at 1634717953426) (:by |u0) |j $ {} (:text |:refer) (:type :leaf) (:at 1630175127717) (:by |u0) |r $ {} :data $ {} @@ -76,12 +67,11 @@ :by |u0 |r $ {} :data $ {} - |T $ {} (:text |lib.util) (:type :leaf) (:at 1634703662332) (:by |u0) + |T $ {} (:text |fetch.util) (:type :leaf) (:at 1634717955112) (:by |u0) |j $ {} (:text |:refer) (:type :leaf) (:at 1633181140100) (:by |u0) |r $ {} :data $ {} - |T $ {} (:text |get-dylib-ext) (:type :leaf) (:at 1633181140100) (:by |u0) - |j $ {} (:text |or-current-path) (:type :leaf) (:at 1633181140100) (:by |u0) + |r $ {} (:text |get-dylib-path) (:type :leaf) (:at 1634715963670) (:by |u0) :type :expr :at 1633181140100 :by |u0 @@ -94,10 +84,17 @@ :type :expr :at 1630171366222 :by |u0 - |lib.test $ {} + |fetch.test $ {} :defs $ {} |run-tests $ {} :data $ {} + |yT $ {} + :data $ {} + |T $ {} (:text |println) (:type :leaf) (:at 1634716143199) (:by |u0) + |j $ {} (:text "|\"sent request") (:type :leaf) (:at 1634716152098) (:by |u0) + :type :expr + :at 1634716142308 + :by |u0 |T $ {} (:text |defn) (:type :leaf) (:at 1633150011172) (:by |u0) |j $ {} (:text |run-tests) (:type :leaf) (:at 1633150008092) (:by |u0) |r $ {} @@ -107,27 +104,47 @@ :by |u0 |v $ {} :data $ {} - |T $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text |println) + |T $ {} (:text |println) (:type :leaf) (:at 1634703837934) (:by |u0) |j $ {} (:text "|\"%%%% test for lib") (:type :leaf) (:at 1634703847178) (:by |u0) :type :expr :at 1634703837934 :by |u0 - |x $ {} (:type :expr) (:by |u0) (:at 1634703837934) + |x $ {} :data $ {} - |T $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text |println) - |j $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text |calcit-filename) - |r $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text |calcit-dirname) - |y $ {} (:type :expr) (:by |u0) (:at 1634703837934) + |T $ {} (:text |println) (:type :leaf) (:at 1634703837934) (:by |u0) + |j $ {} (:text |calcit-filename) (:type :leaf) (:at 1634703837934) (:by |u0) + |r $ {} (:text |calcit-dirname) (:type :leaf) (:at 1634703837934) (:by |u0) + :type :expr + :at 1634703837934 + :by |u0 + |y $ {} :data $ {} - |T $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text |println) - |j $ {} (:type :expr) (:by |u0) (:at 1634703837934) - :data $ {} - |T $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text |path-exists?) - |j $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text "|\"README.md") - |r $ {} (:type :expr) (:by |u0) (:at 1634703837934) + |T $ {} (:text |fetch) (:type :leaf) (:at 1634716141675) (:by |u0) + |j $ {} (:text "|\"http://calcit-lang.org") (:type :leaf) (:at 1634716141675) (:by |u0) + |r $ {} (:text |nil) (:type :leaf) (:at 1634716141675) (:by |u0) + |v $ {} :data $ {} - |T $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text |path-exists?) - |j $ {} (:type :leaf) (:by |u0) (:at 1634703837934) (:text "|\"build.js") + |T $ {} (:text |fn) (:type :leaf) (:at 1634716141675) (:by |u0) + |j $ {} + :data $ {} + |T $ {} (:text |text) (:type :leaf) (:at 1634716141675) (:by |u0) + :type :expr + :at 1634716141675 + :by |u0 + |r $ {} + :data $ {} + |T $ {} (:text |println) (:type :leaf) (:at 1634716141675) (:by |u0) + |j $ {} (:text "|\"loaded") (:type :leaf) (:at 1634716141675) (:by |u0) + |r $ {} (:text |text) (:type :leaf) (:at 1634716141675) (:by |u0) + :type :expr + :at 1634716141675 + :by |u0 + :type :expr + :at 1634716141675 + :by |u0 + :type :expr + :at 1634716141675 + :by |u0 :type :expr :at 1633150008092 :by |u0 @@ -170,17 +187,17 @@ :ns $ {} :data $ {} |T $ {} (:text |ns) (:type :leaf) (:at 1633149625774) (:by |u0) - |j $ {} (:text |lib.test) (:type :leaf) (:at 1633149625774) (:by |u0) + |j $ {} (:text |fetch.test) (:type :leaf) (:at 1633149625774) (:by |u0) |r $ {} :data $ {} |T $ {} (:text |:require) (:type :leaf) (:at 1633149975596) (:by |u0) |j $ {} :data $ {} - |T $ {} (:text |lib.core) (:type :leaf) (:at 1634703858564) (:by |u0) + |T $ {} (:text |fetch.core) (:type :leaf) (:at 1634717944950) (:by |u0) |j $ {} (:text |:refer) (:type :leaf) (:at 1634703859915) (:by |u0) |r $ {} :data $ {} - |T $ {} (:text |path-exists?) (:type :leaf) (:at 1634703860422) (:by |u0) + |T $ {} (:text |fetch) (:type :leaf) (:at 1634716069886) (:by |u0) :type :expr :at 1634703860100 :by |u0 @@ -189,11 +206,11 @@ :by |u0 |r $ {} :data $ {} - |T $ {} (:type :leaf) (:by |u0) (:at 1634703941759) (:text |lib.$meta) - |j $ {} (:type :leaf) (:by |u0) (:at 1634703941759) (:text |:refer) + |T $ {} (:text |fetch.$meta) (:type :leaf) (:at 1634717947304) (:by |u0) + |j $ {} (:text |:refer) (:type :leaf) (:at 1634703941759) (:by |u0) |r $ {} :data $ {} - |T $ {} (:type :leaf) (:by |u0) (:at 1634703941759) (:text |calcit-dirname) + |T $ {} (:text |calcit-dirname) (:type :leaf) (:at 1634703941759) (:by |u0) |j $ {} (:text |calcit-filename) (:type :leaf) (:at 1634703953240) (:by |u0) :type :expr :at 1634703941759 @@ -207,7 +224,7 @@ :type :expr :at 1633149625774 :by |u0 - |lib.util $ {} + |fetch.util $ {} :defs $ {} |get-dylib-ext $ {} :data $ {} @@ -248,6 +265,39 @@ :type :expr :at 1630231398718 :by |u0 + |get-dylib-path $ {} + :data $ {} + |T $ {} (:text |defn) (:type :leaf) (:at 1634715906181) (:by |u0) + |j $ {} (:text |get-dylib-path) (:type :leaf) (:at 1634715906181) (:by |u0) + |r $ {} + :data $ {} + |T $ {} (:text |p) (:type :leaf) (:at 1634715917499) (:by |u0) + :type :expr + :at 1634715906181 + :by |u0 + |v $ {} + :data $ {} + |T $ {} (:text |str) (:type :leaf) (:at 1634715915727) (:by |u0) + |j $ {} + :data $ {} + |T $ {} (:text |or-current-path) (:type :leaf) (:at 1634715915727) (:by |u0) + |j $ {} (:text |calcit-dirname) (:type :leaf) (:at 1634715921685) (:by |u0) + :type :expr + :at 1634715915727 + :by |u0 + |r $ {} (:text |p) (:type :leaf) (:at 1634715944984) (:by |u0) + |v $ {} + :data $ {} + |T $ {} (:text |get-dylib-ext) (:type :leaf) (:at 1634715915727) (:by |u0) + :type :expr + :at 1634715915727 + :by |u0 + :type :expr + :at 1634715915727 + :by |u0 + :type :expr + :at 1634715906181 + :by |u0 |or-current-path $ {} :data $ {} |T $ {} (:text |defn) (:type :leaf) (:at 1630245583936) (:by |u0) @@ -285,7 +335,26 @@ :ns $ {} :data $ {} |T $ {} (:text |ns) (:type :leaf) (:at 1633181044360) (:by |u0) - |j $ {} (:text |lib.util) (:type :leaf) (:at 1633181044360) (:by |u0) + |j $ {} (:text |fetch.util) (:type :leaf) (:at 1633181044360) (:by |u0) + |r $ {} + :data $ {} + |T $ {} (:text |:require) (:type :leaf) (:at 1634715935162) (:by |u0) + |j $ {} + :data $ {} + |T $ {} (:text |fetch.$meta) (:type :leaf) (:at 1634718013389) (:by |u0) + |j $ {} (:text |:refer) (:type :leaf) (:at 1634715935562) (:by |u0) + |r $ {} + :data $ {} + |T $ {} (:text |calcit-dirname) (:type :leaf) (:at 1634715935562) (:by |u0) + :type :expr + :at 1634715935562 + :by |u0 + :type :expr + :at 1634715935562 + :by |u0 + :type :expr + :at 1634715933337 + :by |u0 :type :expr :at 1633181044360 :by |u0 diff --git a/compact.cirru b/compact.cirru index 8eae9b1..baca3ba 100644 --- a/compact.cirru +++ b/compact.cirru @@ -1,38 +1,42 @@ -{} (:package |lib) - :configs $ {} (:init-fn |lib.test/main!) (:reload-fn |lib.test/reload!) +{} (:package |fetch) + :configs $ {} (:init-fn |fetch.test/main!) (:reload-fn |fetch.test/reload!) :modules $ [] :version |0.0.3 :files $ {} - |lib.core $ {} + |fetch.core $ {} :ns $ quote - ns lib.core $ :require - lib.$meta :refer $ calcit-dirname - lib.util :refer $ get-dylib-ext or-current-path + ns fetch.core $ :require + fetch.$meta :refer $ calcit-dirname + fetch.util :refer $ get-dylib-path :defs $ {} - |path-exists? $ quote - defn path-exists? (name) - &call-dylib-edn - str (or-current-path calcit-dirname) "\"/dylibs/libcalcit_std" $ get-dylib-ext - , "\"path_exists" name - |lib.test $ {} + |fetch $ quote + defn fetch (url options cb) + &callback-dylib-edn (get-dylib-path "\"/dylibs/libcalcit_std") "\"fetch" url options cb + |fetch.test $ {} :ns $ quote - ns lib.test $ :require - lib.core :refer $ path-exists? - lib.$meta :refer $ calcit-dirname calcit-filename + ns fetch.test $ :require + fetch.core :refer $ fetch + fetch.$meta :refer $ calcit-dirname calcit-filename :defs $ {} |run-tests $ quote defn run-tests () (println "\"%%%% test for lib") (println calcit-filename calcit-dirname) - println (path-exists? "\"README.md") (path-exists? "\"build.js") + fetch "\"http://calcit-lang.org" nil $ fn (text) (println "\"loaded" text) + println "\"sent request" |main! $ quote defn main! () $ run-tests |reload! $ quote defn reload! $ - |lib.util $ {} - :ns $ quote (ns lib.util) + |fetch.util $ {} + :ns $ quote + ns fetch.util $ :require + fetch.$meta :refer $ calcit-dirname :defs $ {} |get-dylib-ext $ quote defmacro get-dylib-ext () $ case-default (&get-os) "\".so" (:macos "\".dylib") (:windows "\".dll") + |get-dylib-path $ quote + defn get-dylib-path (p) + str (or-current-path calcit-dirname) p $ get-dylib-ext |or-current-path $ quote defn or-current-path (p) if (blank? p) "\"." p diff --git a/src/lib.rs b/src/lib.rs index 8f41366..3df0ec6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +1,20 @@ use cirru_edn::Edn; -use std::path::Path; #[no_mangle] -pub fn path_exists(args: Vec) -> Result { - if args.len() == 1 { +pub fn fetch(args: Vec) -> Result { + if args.len() == 2 { if let Edn::Str(name) = &args[0] { - Ok(Edn::Bool(Path::new(&name).exists())) + match reqwest::blocking::get(name) { + Ok(res) => match res.text() { + Ok(s) => Ok(Edn::Str(s.to_string())), + Err(e) => Err(format!("failed parsing text: {}", e)), + }, + Err(e) => Err(format!("failed request: {}", e)), + } } else { - Err(format!("path-exists? expected 1 filename, got {:?}", args)) + Err(format!("fetch expected 1 url, got {:?}", args)) } } else { - Err(format!("path-exists? expected 1 arg, got {:?}", args)) + Err(format!("fetch expected 2 arguments, got {:?}", args)) } } From b37416d04db0b1ecae84eaa658059e708ccc6efb Mon Sep 17 00:00:00 2001 From: jiyinyiyong Date: Wed, 20 Oct 2021 19:03:14 +0800 Subject: [PATCH 2/2] get error message exposed --- calcit.cirru | 62 ++++++++++++++++++++++++++++++++++++++++++++++----- compact.cirru | 7 +++++- src/lib.rs | 13 ++++++++--- 3 files changed, 73 insertions(+), 9 deletions(-) diff --git a/calcit.cirru b/calcit.cirru index 8cf2b90..e21d52c 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -127,17 +127,69 @@ |T $ {} (:text |fn) (:type :leaf) (:at 1634716141675) (:by |u0) |j $ {} :data $ {} - |T $ {} (:text |text) (:type :leaf) (:at 1634716141675) (:by |u0) + |D $ {} (:text |info) (:type :leaf) (:at 1634727501032) (:by |u0) :type :expr :at 1634716141675 :by |u0 |r $ {} :data $ {} - |T $ {} (:text |println) (:type :leaf) (:at 1634716141675) (:by |u0) - |j $ {} (:text "|\"loaded") (:type :leaf) (:at 1634716141675) (:by |u0) - |r $ {} (:text |text) (:type :leaf) (:at 1634716141675) (:by |u0) + |D $ {} (:text |key-match) (:type :leaf) (:at 1634727504836) (:by |u0) + |H $ {} (:text |info) (:type :leaf) (:at 1634727611280) (:by |u0) + |L $ {} + :data $ {} + |T $ {} + :data $ {} + |T $ {} (:text |:ok) (:type :leaf) (:at 1634727508406) (:by |u0) + |j $ {} (:text |text) (:type :leaf) (:at 1634727511863) (:by |u0) + :type :expr + :at 1634727506210 + :by |u0 + |j $ {} + :data $ {} + |T $ {} (:text |println) (:type :leaf) (:at 1634727513449) (:by |u0) + |j $ {} (:text |text) (:type :leaf) (:at 1634727514676) (:by |u0) + :type :expr + :at 1634727513559 + :by |u0 + :type :expr + :at 1634727505110 + :by |u0 + |P $ {} + :data $ {} + |T $ {} + :data $ {} + |T $ {} (:text |:err) (:type :leaf) (:at 1634727516787) (:by |u0) + |j $ {} (:text |e) (:type :leaf) (:at 1634727518036) (:by |u0) + :type :expr + :at 1634727516052 + :by |u0 + |j $ {} + :data $ {} + |T $ {} (:text |println) (:type :leaf) (:at 1634727520170) (:by |u0) + |j $ {} (:text "|\"Err") (:type :leaf) (:at 1634727523611) (:by |u0) + |r $ {} (:text |e) (:type :leaf) (:at 1634727522139) (:by |u0) + :type :expr + :at 1634727519410 + :by |u0 + :type :expr + :at 1634727515563 + :by |u0 + |R $ {} + :data $ {} + |T $ {} (:text |_) (:type :leaf) (:at 1634727525089) (:by |u0) + |j $ {} + :data $ {} + |T $ {} (:text |println) (:type :leaf) (:at 1634727528537) (:by |u0) + |j $ {} (:text "|\"unknown:") (:type :leaf) (:at 1634727534181) (:by |u0) + |r $ {} (:text |info) (:type :leaf) (:at 1634727536835) (:by |u0) + :type :expr + :at 1634727525997 + :by |u0 + :type :expr + :at 1634727524523 + :by |u0 :type :expr - :at 1634716141675 + :at 1634727503053 :by |u0 :type :expr :at 1634716141675 diff --git a/compact.cirru b/compact.cirru index baca3ba..87d937e 100644 --- a/compact.cirru +++ b/compact.cirru @@ -21,7 +21,12 @@ :defs $ {} |run-tests $ quote defn run-tests () (println "\"%%%% test for lib") (println calcit-filename calcit-dirname) - fetch "\"http://calcit-lang.org" nil $ fn (text) (println "\"loaded" text) + fetch "\"http://calcit-lang.org" nil $ fn (info) + key-match info + :ok text + println text + (:err e) (println "\"Err" e) + _ $ println "\"unknown:" info println "\"sent request" |main! $ quote defn main! () $ run-tests diff --git a/src/lib.rs b/src/lib.rs index 3df0ec6..9cfe87f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +1,22 @@ use cirru_edn::Edn; +pub fn wrap_ok(x: Edn) -> Edn { + Edn::List(vec![Edn::Keyword("ok".to_owned()), x]) +} +pub fn wrap_err(x: Edn) -> Edn { + Edn::List(vec![Edn::Keyword("err".to_owned()), x]) +} + #[no_mangle] pub fn fetch(args: Vec) -> Result { if args.len() == 2 { if let Edn::Str(name) = &args[0] { match reqwest::blocking::get(name) { Ok(res) => match res.text() { - Ok(s) => Ok(Edn::Str(s.to_string())), - Err(e) => Err(format!("failed parsing text: {}", e)), + Ok(s) => Ok(wrap_ok(Edn::Str(s.to_string()))), + Err(e) => Ok(wrap_err(Edn::Str(format!("{}", e)))), }, - Err(e) => Err(format!("failed request: {}", e)), + Err(e) => Ok(wrap_err(Edn::Str(format!("{}", e)))), } } else { Err(format!("fetch expected 1 url, got {:?}", args))