From 1e0c953395cd16cefd0546062a07b3bc5b00d1ab Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Fri, 25 Nov 2022 23:52:27 -0700 Subject: e --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') 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