activitystreams-new/examples/basic.rs

37 lines
930 B
Rust
Raw Normal View History

2020-05-14 03:54:50 +00:00
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(())
}