activitystreams-new/examples/basic.rs
2020-05-13 22:54:50 -05:00

36 lines
930 B
Rust

use activitystreams_new::{
context,
object::{ApObject, Video},
primitives::{XsdAnyUri, XsdString},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut v: ApObject<Video> = Default::default();
v.inner.context = Some(context().into());
v.inner.id = Some(
"https://example.com/@example/lions"
.parse::<XsdAnyUri>()?
.into(),
);
v.inner.url = Some(
"https://example.com/@example/lions/video.webm"
.parse::<XsdAnyUri>()?
.into(),
);
v.inner.summary = Some(XsdString::from("A cool video").into());
v.inner.media_type = Some("video/webm".parse()?);
v.inner.duration = Some("PT4M20S".parse()?);
println!("Video, {:#?}", v);
let s = serde_json::to_string(&v)?;
println!("json, {}", s);
let v: ApObject<Video> = serde_json::from_str(&s)?;
println!("Video again, {:#?}", v);
Ok(())
}