activitystreams-new/examples/basic.rs
2020-06-03 12:31:54 -05:00

31 lines
849 B
Rust

use activitystreams_new::{
context,
object::{ApObject, Video},
prelude::*,
primitives::XsdAnyUri,
};
fn main() -> Result<(), anyhow::Error> {
let mut video = ApObject::new(Video::new());
video
.set_context(context())
.set_id("https://example.com/@example/lions".parse()?)
.set_media_type("video/webm".parse()?)
.set_url("https://example.com/@example/lions/video.webm".parse::<XsdAnyUri>()?)
.set_summary("A cool video".to_owned())
.set_duration("PT4M20S".parse()?)
.set_shares("https://example.com/@example/lions/video.webm#shares".parse()?);
println!("Video, {:#?}", video);
let s = serde_json::to_string(&video)?;
println!("json, {}", s);
let v: ApObject<Video> = serde_json::from_str(&s)?;
println!("Video again, {:#?}", v);
Ok(())
}