aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-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]