Avoid cloning generated id when submitting paste
Diff
src/main.rs | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
@@ -55,8 +55,9 @@
#[post("/", data = "<input>")]
fn submit(input: Form<IndexForm>) -> Redirect {
let id = generate_id();
store_paste(id.clone(), input.into_inner().val);
Redirect::to(uri!(show_paste: id))
let uri = uri!(show_paste: &id);
store_paste(id, input.into_inner().val);
Redirect::to(uri)
}
#[put("/", data = "<input>")]
@@ -65,11 +66,13 @@
input.open().take(1024 * 1000).read_to_string(&mut data)?;
let id = generate_id();
store_paste(id.clone(), data);
let uri = uri!(show_paste: &id);
store_paste(id, data);
match *host {
Some(host) => Ok(format!("https://{}{}", host, uri!(show_paste: id))),
None => Ok(id),
Some(host) => Ok(format!("https://{}{}", host, uri)),
None => Ok(format!("{}", uri)),
}
}