Skip to content

Instantly share code, notes, and snippets.

@flosse
Last active November 11, 2016 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flosse/cf7713847716d4d134b6fe3fc6a791f3 to your computer and use it in GitHub Desktop.
Save flosse/cf7713847716d4d134b6fe3fc6a791f3 to your computer and use it in GitHub Desktop.
jfs example
extern crate jfs;
extern crate rustc_serialize;
use jfs::{Config,Store};
#[derive(Debug,Clone, RustcEncodable, RustcDecodable)]
struct Tag {
id: String,
name: String,
owner: String
}
#[derive(Debug,Clone, RustcEncodable, RustcDecodable)]
struct Member {
id: String,
name: String
}
fn main(){
let mut cfg = Config::default();
cfg.pretty = true;
cfg.single = true;
let tags = Store::new_with_cfg("tags", cfg.clone()).unwrap();
let members = Store::new_with_cfg("members", cfg).unwrap();
let m1 = Member{id: "b".into(), name: "Bob".into() };
let m2 = Member{id: "a".into(), name: "Alice".into() };
let t1 = Tag{id: "one".into(), name: "foo".into(), owner: m1.id.clone() };
let t2 = Tag{id: "two".into(), name: "bar".into(), owner: m2.id.clone() };
tags.save_with_id(&t1,&t1.id).unwrap();
tags.save_with_id(&t2,&t2.id).unwrap();
members.save_with_id(&m1,&m1.id).unwrap();
members.save_with_id(&m2,&m2.id).unwrap();
let owner = "b";
let tags_owned_by_b = tags
.get_all::<Tag>().unwrap()
.values()
.cloned()
.filter(|t| t.owner == owner )
.collect::<Vec<Tag>>();
println!("{:?}",tags_owned_by_b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment