pub mod tree {
polygraph_macro::schema! {
type Tree;
pub struct Surname(pub String);
pub struct Person {
pub last_name: Key<Surname>,
pub father: Option<Key<Person>>,
pub mother: Option<Key<Person>>,
pub name: String,
pub dog: KeySet<Dog>,
}
pub struct Dog {
pub name: String,
}
}
#[test]
fn test() {
let mut db = Tree::new();
let mickey = db.insert_dog(Dog {
name: "Mickey".to_string(),
});
let minnie = db.insert_dog(Dog {
name: "Minnie".to_string(),
});
let my_dogs: tinyset::Set64<_> = [mickey, minnie].iter().cloned().collect();
let roundy = db.insert_surname(Surname("Roundy".to_string()));
let maiden_name = db.insert_surname(Surname("Maiden".to_string()));
let me = db.insert_person(Person {
last_name: roundy,
father: None,
mother: None,
name: "David".to_string(),
dog: my_dogs.clone(),
});
let wife = db.insert_person(Person {
last_name: maiden_name,
father: None,
mother: None,
name: "Monica".to_string(),
dog: my_dogs.clone(),
});
let kid = db.insert_person(Person {
last_name: roundy,
father: Some(me),
mother: Some(wife),
name: "Kid".to_string(),
dog: my_dogs.clone(),
});
assert_eq!(me.d(&db).last_name.d(&db).0, "Roundy");
assert_eq!(wife.d(&db).last_name.d(&db).0, "Maiden");
assert!(roundy.d(&db).last_name_of.contains(me));
assert!(roundy.d(&db).last_name_of.contains(kid));
assert!(me.d(&db).father_of.contains(kid));
assert!(!me.d(&db).father_of.contains(wife));
assert!(wife.d(&db).mother_of.contains(kid));
assert!(minnie.d(&db).dog_of.contains(me));
assert!(minnie.d(&db).dog_of.contains(wife));
assert!(minnie.d(&db).dog_of.contains(kid));
assert_eq!(db[db[me].last_name].0, "Roundy");
assert_eq!(db[db[wife].last_name].0, "Maiden");
assert!(db[roundy].last_name_of.contains(me));
assert!(db[roundy].last_name_of.contains(kid));
assert!(db[me].father_of.contains(kid));
assert!(!db[me].father_of.contains(wife));
}
}
polygraph_macro::schema! {
type Schema;
pub struct Test {
pub name: String,
}
pub struct Foo(pub u64);
}
pub enum NotHere {
A,
B,
}