From 1e0c953395cd16cefd0546062a07b3bc5b00d1ab Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Fri, 25 Nov 2022 23:52:27 -0700 Subject: e --- Cargo.lock | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + prechoster.json | 2 +- src/main.rs | 14 +++++-- 4 files changed, 123 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1423d87..56fb618 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,6 +75,12 @@ dependencies = [ "syn", ] +[[package]] +name = "async_once" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ce4f10ea3abcd6617873bae9f91d1c5332b4a778bd9ce34d0cd517474c1de82" + [[package]] name = "atomic" version = "0.5.1" @@ -134,6 +140,43 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +[[package]] +name = "cached" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b4147cd94d5fbdc2ab71b11d50a2f45493625576b3bb70257f59eedea69f3d" +dependencies = [ + "async-trait", + "async_once", + "cached_proc_macro", + "cached_proc_macro_types", + "futures", + "hashbrown", + "instant", + "lazy_static", + "once_cell", + "thiserror", + "tokio", +] + +[[package]] +name = "cached_proc_macro" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "751f7f4e7a091545e7f6c65bacc404eaee7e87bfb1f9ece234a1caa173dc16f2" +dependencies = [ + "cached_proc_macro_types", + "darling", + "quote", + "syn", +] + +[[package]] +name = "cached_proc_macro_types" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" + [[package]] name = "cc" version = "1.0.77" @@ -203,6 +246,41 @@ dependencies = [ "cipher", ] +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "devise" version = "0.3.1" @@ -516,6 +594,12 @@ dependencies = [ "want", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "indexmap" version = "1.9.2" @@ -574,6 +658,7 @@ name = "linja-pona-svginator" version = "0.1.0" dependencies = [ "anyhow", + "cached", "quick-xml", "rocket", ] @@ -1131,6 +1216,12 @@ dependencies = [ "loom", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.4.1" @@ -1162,6 +1253,26 @@ dependencies = [ "winapi", ] +[[package]] +name = "thiserror" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.4" diff --git a/Cargo.toml b/Cargo.toml index f5197f0..870c875 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" [dependencies] anyhow = "1.0.66" +cached = "0.40.0" quick-xml = "0.26.0" rocket = "0.5.0-rc.2" diff --git a/prechoster.json b/prechoster.json index 180b67b..43952a7 100644 --- a/prechoster.json +++ b/prechoster.json @@ -1 +1 @@ -{"modules":[{"id":"00423c5ee8323e1e","data":{"name":"Toki","contents":"\n\n{text}{textEn}{text}\n\n\n"},"pluginId":"source.svelte-component","sends":[],"namedSends":{"5e0a6640c309d9dd":["Toki"]},"graphPos":null},{"id":"5e0a6640c309d9dd","data":{"contents":"\n\n

\n \n \n \n \n \n \n \n \n \n .\n

\n\n

\n \n \n \n \n \n \n \n \n .\n \n \n \n \n .\n \n \n \n \n \n \n \n .\n

\n\n

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n .\n \n \n \n \n \n .\n

\n\n\n"},"pluginId":"source.svelte","sends":["a019876d3132d78a"],"namedSends":{},"graphPos":null},{"id":"a019876d3132d78a","data":{"mode":"attr"},"pluginId":"transform.style-inliner","sends":["output"],"namedSends":{},"graphPos":null}]} \ No newline at end of file +{"modules":[{"id":"00423c5ee8323e1e","data":{"name":"Toki","contents":"\n\n{text}{textEn}{text}\n\n\n"},"pluginId":"source.svelte-component","sends":[],"namedSends":{"5e0a6640c309d9dd":["Toki"]},"graphPos":null},{"id":"5e0a6640c309d9dd","data":{"contents":"\n\n

\n \n \n \n \n \n \n \n \n \n .\n

\n\n

\n \n \n \n \n \n \n \n \n .\n \n \n \n \n .\n \n \n \n \n \n \n \n .\n

\n\n

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n .\n \n \n \n \n \n .\n

\n\n\n"},"pluginId":"source.svelte","sends":["a019876d3132d78a"],"namedSends":{},"graphPos":null},{"id":"a019876d3132d78a","data":{"mode":"attr"},"pluginId":"transform.style-inliner","sends":["output"],"namedSends":{},"graphPos":null}]} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 235023a..1d7e27e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate rocket; +use cached::proc_macro::cached; use quick_xml::events::BytesText; use quick_xml::Writer; use rocket::http::{ContentType, Status}; @@ -64,6 +65,14 @@ fn to_final_svg(text: &str) -> anyhow::Result { Ok(result) } +#[cached] +fn get_result(text: String) -> Result<(ContentType, String), (Status, String)> { + match to_final_svg(&text) { + Ok(svg) => Ok((ContentType::SVG, svg)), + Err(e) => Err((Status::InternalServerError, e.to_string())), + } +} + #[get("/")] fn index() -> &'static str { "Hello, world!" @@ -71,10 +80,7 @@ fn index() -> &'static str { #[get("/render/")] fn render(text: &str) -> Result<(ContentType, String), (Status, String)> { - match to_final_svg(text) { - Ok(svg) => Ok((ContentType::SVG, svg)), - Err(e) => Err((Status::InternalServerError, e.to_string())), - } + get_result(text.to_string()) } #[rocket::main] -- cgit v1.2.3