extern crate async_std;
extern crate iref;
#[macro_use]
extern crate iref_enum;
extern crate json_ld;
use json_ld::{context, Document, Lexicon, NoLoader, Object};
use serde_json::Value;
#[derive(IriEnum, Clone, Copy, PartialEq, Eq, Hash)]
#[iri_prefix("foaf" = "http://xmlns.com/foaf/0.1/")]
pub enum Foaf {
#[iri("foaf:name")]
Name,
#[iri("foaf:mbox")]
Mbox,
}
type Id = Lexicon<Foaf>;
#[async_std::main]
async fn main() {
let doc: Value = serde_json::from_str(
r#"
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name",
"email": "http://xmlns.com/foaf/0.1/mbox"
},
"@id": "timothee.haudebourg.net",
"name": "Timothée Haudebourg",
"email": "author@haudebourg.net"
}
"#,
)
.unwrap();
let mut loader = NoLoader::<Value>::new();
let expanded_doc = doc
.expand::<context::Json<Value, Id>, _>(&mut loader)
.await
.unwrap();
for object in expanded_doc {
if let Object::Node(node) = object.as_ref() {
println!("node: {}", node.id().unwrap()); for name in node.get(Foaf::Name) {
println!("name: {}", name.as_str().unwrap());
}
for name in node.get(Foaf::Mbox) {
println!("email: {}", name.as_str().unwrap());
}
}
}
}