reorganize std::fs and std::io imports

This commit is contained in:
la Fleur 2020-11-10 11:25:21 +01:00
parent 79d66cfc4a
commit 84354c3834
1 changed files with 6 additions and 11 deletions

View File

@ -2,14 +2,12 @@
#[macro_use] extern crate rocket;
//use std::fmt::Display;
use std::result::Result;
use std::fs;
//use rocket::Request;
use rocket_contrib::templates::Template;
//use rocket::request::{Outcome, Request, FromRequest, FromParam};
use std::io;
use rocket::request::{Request, FromParam};
//use rocket::http::Status;
use rocket::http::RawStr;
use rocket_contrib::templates::Template;
#[derive(serde::Serialize, Debug)]
struct User {
@ -20,7 +18,7 @@ struct User {
impl<'r> FromParam<'r> for User {
type Error = &'r RawStr;
fn from_param(param: &'r RawStr) -> std::result::Result<Self, Self::Error> {
fn from_param(param: &'r RawStr) -> Result<Self, Self::Error> {
let filename = format!("users/{}.md", param);
let content = fs::read_to_string(&filename);
match content {
@ -30,7 +28,7 @@ impl<'r> FromParam<'r> for User {
}
}
fn list_users() -> std::io::Result<Vec<String>> {
fn list_users() -> io::Result<Vec<String>> {
let mut users: Vec<String> = vec!();
for path in fs::read_dir("users")? {
let file = path?;
@ -63,16 +61,13 @@ fn show(user: User) -> Template {
}
#[get("/")]
fn index() -> std::io::Result<Template> {
fn index() -> io::Result<Template> {
let users = list_users()?;
let context = IndexContext { name: "home", items: users };
Ok(Template::render("index", &context))
}
fn main() {
//let user_map = get_user_map();
//println!("{:#?}", user_map);
rocket::ignite()
.attach(Template::fairing())
.mount("/", routes![index, show])