activitystreams-new/examples/basic.rs
2020-05-14 11:23:38 -05:00

30 lines
806 B
Rust

use activitystreams_new::{
context,
object::{ApObject, Video},
primitives::{XsdAnyUri, XsdString},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let video = Video::builder()
.context(context())
.id("https://example.com/@example/lions".parse::<XsdAnyUri>()?)
.url("https://example.com/@example/lions/video.webm".parse::<XsdAnyUri>()?)
.summary(XsdString::from("A cool video"))
.media_type("video/webm".parse()?)
.duration("PT4M20S".parse()?)
.build();
let v = ApObject::builder().inner(video).build();
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(())
}