activitystreams-new/examples/basic.rs
asonix 4f4cec8fec License, Readme, start documentation
Done:
- Base

Todo:
- Primitives
- Unparsed
- Object
- Actor
- Activity
- Link
2020-05-15 20:08:43 -05:00

31 lines
877 B
Rust

use activitystreams_new::{
context,
object::{ApObject, Video},
prelude::*,
primitives::{XsdAnyUri, XsdString},
};
fn main() -> Result<(), anyhow::Error> {
let mut video: ApObject<Video> = ApObject::default();
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(XsdString::from("A cool video"))
.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(())
}