clean up the dogs example

master
Ondřej Hruška 5 years ago
parent f8d5445cdc
commit 4046e7f185
Signed by untrusted user: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 25
      examples/dog_list/main.rs

@ -2,7 +2,6 @@
#[macro_use]
extern crate rocket;
use rocket::request::Form;
use rocket::response::content::Html;
use rocket::response::Redirect;
@ -30,38 +29,23 @@ fn index(session: Session) -> Html<String> {
<ul>
"#,
);
session.tap(|sess| {
for (n, dog) in sess.iter().enumerate() {
page.push_str(&format!(
r#"
<li>&#x1F436; {} <a href="/remove/{}">Remove</a></li>
"#,
r#"<li>&#x1F436; {} <a href="/remove/{}">Remove</a></li>"#,
dog, n
));
}
});
page.push_str(
r#"
</ul>
"#,
);
page.push_str("</ul>");
Html(page)
}
#[derive(FromForm)]
struct AddForm {
name: String,
}
#[post("/add", data = "<dog>")]
fn add(session: Session, dog: Form<AddForm>) -> Redirect {
fn add(session: Session, dog: String) -> Redirect {
session.tap(move |sess| {
sess.push(dog.into_inner().name);
sess.push(dog);
});
Redirect::found("/")
}
@ -72,6 +56,5 @@ fn remove(session: Session, dog: usize) -> Redirect {
sess.remove(dog);
}
});
Redirect::found("/")
}

Loading…
Cancel
Save