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.
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
Hard to read/understand. Possible improvements: aan enum? is used internally?
inside JSON objects/arrays, using serde?
inside of JSON object?
What is a "failed state"?
Hard to read/understand. Possible improvements:
~~a~~an enum?
*is* used internally?
inside JSON objects/arrays, using serde?
inside ~~of~~ JSON object?
What is a "failed state"?
"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?
"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?
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
custom_error! { pub IncorrectPointer{pointer: String} = "Incorrect pointer is specified: {pointer}" }
/// This is a enum that used internally to refer to values inside of
Hard to read/understand. Possible improvements:
aan enum?is used internally?
inside JSON objects/arrays, using serde?
inside
ofJSON object?What is a "failed state"?
Invalid,
}
/// Implements database's file by wrapping JSON value (`serde_json::Value`)
"Stores database in a JSON file"?
}
impl File {
/// Creates an empty file that will contain an empty JSON object.
Empty file cannot contain anything.
}
}
/// Loads JSON value from the specified file.
But it accepts file_contents, not file/filepath?
})
}
/// Returns file's "root", - JSON value contained inside it.
,-? Hard to understand.
&self.contents
}
/// Attempts to return JSON value, corresponding to the given JSON pointer.
Remove "attempts"?
/// 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
/// it will be added.
/// 3. Otherwise an error will be raise.
///
/// If array needs to be expanded, - missing values will be filled
,-?
/// 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?
Ok(())
}
/// Removes (and returns) value specified by theJSON pointer.
Missing space
}
/// 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.
}
}
/// Helper method to create a value if missing (as `json!(null)`).
What's missing?
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?
Ok(())
}
/// Helper method, - converts JSON pointer into auxiliary `ValueReference` enum.
,-?
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.
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?..
}
}
// Helper function to disassemble JSON path.
Into what?
Ok(())
}
/// helper function to read a group from a given subdirectory:
helper->Helper
Containing what?
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.
/// 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
/// 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
}
/// Creates a new empty group.
/// Will produce error if group already exists.
Produce -> return
Ok(())
}
/// Checks if specified file (in a specified group) is contained in the database.
contained -> stored
.expect("Missing value that was just inserted."))
}
/// Removes specified file (in a specified group).
Braces aren't needed here.
}
/// Removes specified file (in a specified group).
/// Will produce error if file does not exist.
produce -> return
Ok(())
}
/// Returns immutable reference to the specified file (in a specified group) as `file::File`.
Braces aren't needed here.
}
}
// Helper methods that return (im)mutable reference to `HashMap`
(im)? Why?
impl Drop for TestCleanup {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.path);
Why _?
_ => (),
}
let db = database::Database::load(Path::new(filename));
/*match db {
Remove commented code?
/// 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.
let group_index = self.group_index(group_name)?;
Ok(&mut (&mut self.groups[group_index]).files)
}
Missing doc.
feature_databaseto [WIP] feature_database 3 years agoReviewers