pindell-matt / rust_bucket

Simple JSON key-value store implemented in Rust
Other
11 stars 6 forks source link

find #12

Closed selfup closed 8 years ago

selfup commented 8 years ago

Once the serde_json_schema PR is merged, write a find function that let's the user dictate the table and the id of the record in the records Hash.

pub fn find<T: Serialize + Deserialize>(table: &str, id: &str) -> HashMap<String, T> {

Something like this would be a good start.

An additional option would be to build a separate Struct to return a nice object to our users.

#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct SingleRecord<T: Serialize> {
    pub record: HashMap<String, T>,
}

pub fn find<T: Serialize + Deserialize>(table: &str, id: &str) -> SingleRecord<T> {

This way you can use serde to serialize/deserialize a good object.

Just some high level examples.

I wrote two helper methods to be more DRY on the find branch: Here are the LOC to look at

This is the branch you should be working on after the serde_json_schema PR is merged.