[WIP] feature_database #8
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature_database"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This implements a a simple JSON-based database, that works through loading full self-copy into the memory. Should be more than enough for the needs of kf modding.
Closes #6
Closes #1
Test comment
Sorry for spam
@ -0,0 +9,4 @@custom_error! { pub IncorrectPointer{pointer: String} = "Incorrect pointer is specified: {pointer}" }/// This is a enum that used internally to refer to values inside ofHard to read/understand. Possible improvements:
aan enum?is used internally?
inside JSON objects/arrays, using serde?
inside
ofJSON object?What is a "failed state"?
@ -0,0 +26,4 @@Invalid,}/// Implements database's file by wrapping JSON value (`serde_json::Value`)"Stores database in a JSON file"?
@ -0,0 +41,4 @@}impl File {/// Creates an empty file that will contain an empty JSON object.Empty file cannot contain anything.
@ -0,0 +48,4 @@}}/// Loads JSON value from the specified file.But it accepts file_contents, not file/filepath?
@ -0,0 +55,4 @@})}/// Returns file's "root", - JSON value contained inside it.,-? Hard to understand.
@ -0,0 +60,4 @@&self.contents}/// Attempts to return JSON value, corresponding to the given JSON pointer.Remove "attempts"?
@ -0,0 +79,4 @@/// 1. If it already exists, - it will be overwritten./// 2. If it does not exist, but it's parent object/array does -/// it will be added./// 3. Otherwise an error will be raise.raised
@ -0,0 +81,4 @@/// it will be added./// 3. Otherwise an error will be raise.////// If array needs to be expanded, - missing values will be filled,-?
@ -0,0 +82,4 @@/// 3. Otherwise an error will be raise.////// If array needs to be expanded, - missing values will be filled/// with `json!(null)`, i.e. inserting `7` at index `5` in array `[1, 2, 3]`Sounds like a hack/bug - why is it like this?
@ -0,0 +103,4 @@Ok(())}/// Removes (and returns) value specified by theJSON pointer.Missing space
@ -0,0 +104,4 @@}/// Removes (and returns) value specified by theJSON pointer./// If it did not exist - returns `None`.Remove 2nd line? A simple "if it exists" should be enough.
@ -0,0 +118,4 @@}}/// Helper method to create a value if missing (as `json!(null)`).What's missing?
@ -0,0 +135,4 @@ValueReference::Array(vec, variable_index) => {// We've checked at the beginning of this method that value// at `variable_index` does not exist, which guarantees// that array is to short and we won't shrink it"too short"
Also, the " We've checked ... we won't shrink it" part is hard to understand - checked what where? Why can't we shrink it? How are those 2 things connected?
@ -0,0 +147,4 @@Ok(())}/// Helper method, - converts JSON pointer into auxiliary `ValueReference` enum.,-?
@ -0,0 +152,4 @@if pointer.is_empty() {return ValueReference::Invalid;}// Extract variable name (that `pointer` points to)Need a link to https://tools.ietf.org/html/rfc6901 somewhere to explain what exactly "JSON pointer" is.
@ -0,0 +169,4 @@Some(v) => v,_ => return ValueReference::Invalid,};// For arrays we also need to confirm validity of the variable name"validity of the variable name" - which means?..
@ -0,0 +185,4 @@}}// Helper function to disassemble JSON path.Into what?
@ -0,0 +118,4 @@Ok(())}/// helper function to read a group from a given subdirectory:helper->Helper
Containing what?
@ -0,0 +197,4 @@fn get_file_name(path: &path::Path) -> String {path.file_stem().and_then(|x| x.to_str()).unwrap_or_default()Wont this silently cause errors by replacing given path that cannot be converted with empty strings?
Same thing in fn below this one.
@ -0,0 +31,4 @@/// This database is only supposed to hold a relatively small amount of data/// that:////// 1. can be freely and full loaded into memory;full -> fully
@ -0,0 +81,4 @@/// Directory must contain valid database and be readable.////// This method will also remove all data from the current database's path/// and fail if it can't.fail -> will fail
@ -0,0 +132,4 @@}/// Creates a new empty group./// Will produce error if group already exists.Produce -> return
@ -0,0 +151,4 @@Ok(())}/// Checks if specified file (in a specified group) is contained in the database.contained -> stored
@ -0,0 +176,4 @@.expect("Missing value that was just inserted."))}/// Removes specified file (in a specified group).Braces aren't needed here.
@ -0,0 +177,4 @@}/// Removes specified file (in a specified group)./// Will produce error if file does not exist.produce -> return
@ -0,0 +192,4 @@Ok(())}/// Returns immutable reference to the specified file (in a specified group) as `file::File`.Braces aren't needed here.
@ -0,0 +232,4 @@}}// Helper methods that return (im)mutable reference to `HashMap`(im)? Why?
@ -0,0 +15,4 @@impl Drop for TestCleanup {fn drop(&mut self) {let _ = fs::remove_dir_all(&self.path);Why _?
@ -11,2 +11,2 @@_ => (),}let db = database::Database::load(Path::new(filename));/*match db {Remove commented code?
@ -0,0 +29,4 @@/// Implements database's file by wrapping JSON value (`serde_json::Value`)/// and providing several convenient accessor methods.#[derive(Debug)]pub struct File {Rename to JsonFile?
Also, it's not even a file.
@ -0,0 +238,4 @@let group_index = self.group_index(group_name)?;Ok(&mut (&mut self.groups[group_index]).files)}Missing doc.
feature_databaseto [WIP] feature_databaseCheckout
From your project repository, check out a new branch and test the changes.