diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..65804c2 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,6 @@ +edition = "2021" +newline_style = "Unix" +match_block_trailing_comma = true +fn_params_layout = "Compressed" +use_field_init_shorthand = true +use_small_heuristics = "Max" diff --git a/src/key_value.rs b/src/key_value.rs index 6b00af6..8aabce3 100644 --- a/src/key_value.rs +++ b/src/key_value.rs @@ -1,7 +1,7 @@ -use rusqlite::{Connection, Result, params}; -use std::ops::Index; +use rusqlite::{params, Connection, Result}; use std::cell::Cell; use std::collections::HashSet; +use std::ops::Index; /// Simple SQLite-backed key/value store. /// @@ -27,7 +27,7 @@ impl KeyValueStore { )", [], )?; - Ok(Self { conn, has_write_errors: Cell::new(false), }) + Ok(Self { conn, has_write_errors: Cell::new(false) }) } /// Report if any write errors occurred. @@ -53,11 +53,13 @@ impl KeyValueStore { /// Will panic on error. (The idea is to call this a bunch of times at boot, /// to populate the DB if missing / newly created, and not use it after.) pub fn default(&self, key: &str, value: &str) { - self.conn.execute( - "INSERT INTO kv_store (key, value) VALUES (?1, ?2) + self.conn + .execute( + "INSERT INTO kv_store (key, value) VALUES (?1, ?2) ON CONFLICT(key) DO NOTHING", - params![key, value], - ).expect(&format!("Failed to write default at key: {}", key)); + params![key, value], + ) + .expect(&format!("Failed to write default at key: {}", key)); } /// Write a `key`/`value` pair to the DB. @@ -74,7 +76,7 @@ impl KeyValueStore { eprintln!("Failed DB write: ({}, {})", key, value); self.has_write_errors.set(true); Err(e) - } + }, } } @@ -88,7 +90,7 @@ impl KeyValueStore { eprintln!("Failed DB write: ({}, NULL)", key); self.has_write_errors.set(true); Err(e) - } + }, } }