diff options
Diffstat (limited to 'src/schema.rs')
-rw-r--r-- | src/schema.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/schema.rs b/src/schema.rs index 33dc301..6f2f1f3 100644 --- a/src/schema.rs +++ b/src/schema.rs | |||
@@ -50,7 +50,8 @@ fn create_db_with_last_block(path: String) -> Db { | |||
50 | let block: Block = serde_json::from_str(json).unwrap(); | 50 | let block: Block = serde_json::from_str(json).unwrap(); |
51 | let db = Db::new(); | 51 | let db = Db::new(); |
52 | *db.blockchain.write() = block; | 52 | *db.blockchain.write() = block; |
53 | return db; | 53 | |
54 | db | ||
54 | } | 55 | } |
55 | 56 | ||
56 | /// Creates a new database, uses the previous last block if one exists | 57 | /// Creates a new database, uses the previous last block if one exists |
@@ -59,9 +60,9 @@ pub fn create_database() -> Db { | |||
59 | fs::create_dir_all("users").unwrap(); | 60 | fs::create_dir_all("users").unwrap(); |
60 | let (res, path) = last_block_exists(); | 61 | let (res, path) = last_block_exists(); |
61 | if res { | 62 | if res { |
62 | return create_db_with_last_block(path); | 63 | create_db_with_last_block(path) |
63 | } else { | 64 | } else { |
64 | return Db::new(); | 65 | Db::new() |
65 | } | 66 | } |
66 | } | 67 | } |
67 | 68 | ||
@@ -168,6 +169,12 @@ impl Block { | |||
168 | } | 169 | } |
169 | } | 170 | } |
170 | 171 | ||
172 | impl Default for Block { | ||
173 | fn default() -> Self { | ||
174 | Self::new() | ||
175 | } | ||
176 | } | ||
177 | |||
171 | /// Simply a Student | 178 | /// Simply a Student |
172 | #[derive(Serialize, Deserialize, Debug, PartialEq)] | 179 | #[derive(Serialize, Deserialize, Debug, PartialEq)] |
173 | pub struct User { | 180 | pub struct User { |
@@ -247,7 +254,7 @@ impl MetuId { | |||
247 | pub fn new(id: String, pwd: String) -> Option<Self> { | 254 | pub fn new(id: String, pwd: String) -> Option<Self> { |
248 | if OUR_STUDENTS.contains(&(&*id, &*pwd)) { | 255 | if OUR_STUDENTS.contains(&(&*id, &*pwd)) { |
249 | Some(MetuId { | 256 | Some(MetuId { |
250 | id: id, | 257 | id, |
251 | passwd: pwd, | 258 | passwd: pwd, |
252 | }) | 259 | }) |
253 | } else { | 260 | } else { |