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:
parent
38801c5625
commit
f65fde7378
|
@ -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> {
|
||||
|
|
|
@ -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>>> {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -84,5 +84,3 @@ impl List {
|
|||
lists
|
||||
}
|
||||
}
|
||||
|
||||
pub type ListStore = RwLock<Vec<List>>;
|
|
@ -0,0 +1 @@
|
|||
pub mod list;
|
Loading…
Reference in New Issue