activitystreams-new/examples/basic.rs

33 lines
857 B
Rust
Raw Normal View History

2020-05-14 03:54:50 +00:00
use activitystreams_new::{
context,
object::{ApObject, Video},
prelude::*,
2020-06-03 20:35:45 +00:00
uri,
2020-05-14 03:54:50 +00:00
};
use chrono::Duration;
2020-05-14 03:54:50 +00:00
fn main() -> Result<(), anyhow::Error> {
2020-05-17 20:04:10 +00:00
let mut video = ApObject::new(Video::new());
2020-05-14 16:23:38 +00:00
video
.set_context(context())
2020-06-03 20:35:45 +00:00
.set_id(uri!("https://example.com/@example/lions"))
.set_media_type("video/webm".parse()?)
2020-06-03 20:35:45 +00:00
.set_url(uri!("https://example.com/@example/lions/video.webm"))
2020-06-03 17:31:54 +00:00
.set_summary("A cool video".to_owned())
.set_duration(Duration::minutes(4) + Duration::seconds(20))
2020-06-03 20:35:45 +00:00
.set_shares(uri!("https://example.com/@example/lions/video.webm#shares"));
2020-05-14 03:54:50 +00:00
println!("Video, {:#?}", video);
2020-05-14 03:54:50 +00:00
let s = serde_json::to_string(&video)?;
2020-05-14 03:54:50 +00:00
println!("json, {}", s);
let v: ApObject<Video> = serde_json::from_str(&s)?;
println!("Video again, {:#?}", v);
Ok(())
}