Move the List struct to a modules submodule

Move the state type ListStore back to main.rs, it is used for
a global state object (like a DB connection, etc.)
This commit is contained in:
Paul van Tilburg 2017-12-30 22:23:16 +01:00
parent 38801c5625
commit f65fde7378
5 changed files with 8 additions and 6 deletions

View File

@ -1,7 +1,7 @@
use list::ListStore;
use rocket::State;
use rocket_contrib::Template;
use std::collections::HashMap;
use super::super::ListStore;
#[derive(Serialize)]
struct IndexTemplateContext<'a> {

View File

@ -1,6 +1,7 @@
use list::{List, ListStore};
use rocket::State;
use rocket_contrib::Json;
use super::super::ListStore;
use super::super::models::list::List;
#[get("/", format = "application/json")]
fn index(lists: State<ListStore>) -> Option<Json<Vec<List>>> {

View File

@ -9,14 +9,16 @@ extern crate rocket_contrib;
#[macro_use] extern crate serde_derive;
extern crate serde_json;
mod list;
mod handlers;
mod models;
use rocket::Rocket;
use std::sync::RwLock;
pub type ListStore = RwLock<Vec<models::list::List>>;
fn rocket() -> Rocket {
let lists = list::List::load_all();
let lists = models::list::List::load_all();
rocket::ignite()
.manage(RwLock::new(lists))
.mount("/", routes![handlers::home::index,

View File

@ -84,5 +84,3 @@ impl List {
lists
}
}
pub type ListStore = RwLock<Vec<List>>;

1
src/models/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod list;