aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2022-11-25 23:52:27 -0700
committerMelody Horn <melody@boringcactus.com>2022-11-25 23:52:27 -0700
commit1e0c953395cd16cefd0546062a07b3bc5b00d1ab (patch)
tree2691735288eaa7bc46e26f83a15469c54e5a10a8 /src
parentc13fd19d83d923c4bc5a5dc19c301ab6b4d0c73a (diff)
downloadlinja-pona-svginator-1e0c953395cd16cefd0546062a07b3bc5b00d1ab.tar.gz
linja-pona-svginator-1e0c953395cd16cefd0546062a07b3bc5b00d1ab.zip
Diffstat (limited to 'src')
-rw-r--r--src/main.rs14
1 files changed, 10 insertions, 4 deletions
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<String> {
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/<text>")]
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]