activitystreams/examples/basic.rs

33 lines
853 B
Rust
Raw Normal View History

2020-03-19 01:23:45 +00:00
use activitystreams::{
2020-07-25 22:11:42 +00:00
context,
object::{ApObject, Video},
prelude::*,
uri,
2020-03-19 01:23:45 +00:00
};
2020-07-25 22:11:42 +00:00
use chrono::Duration;
2020-03-10 03:54:41 +00:00
2020-07-25 22:11:42 +00:00
fn main() -> Result<(), anyhow::Error> {
let mut video = ApObject::new(Video::new());
2020-03-10 03:54:41 +00:00
2020-07-25 22:11:42 +00:00
video
.set_context(context())
.set_id(uri!("https://example.com/@example/lions"))
.set_media_type("video/webm".parse()?)
.set_url(uri!("https://example.com/@example/lions/video.webm"))
.set_summary("A cool video".to_owned())
.set_duration(Duration::minutes(4) + Duration::seconds(20))
.set_shares(uri!("https://example.com/@example/lions/video.webm#shares"));
2020-03-10 03:54:41 +00:00
2020-07-25 22:11:42 +00:00
println!("Video, {:#?}", video);
2020-03-10 03:54:41 +00:00
2020-07-25 22:11:42 +00:00
let s = serde_json::to_string(&video)?;
2020-03-10 03:54:41 +00:00
println!("json, {}", s);
2020-07-25 22:11:42 +00:00
let v: ApObject<Video> = serde_json::from_str(&s)?;
2020-03-10 03:54:41 +00:00
println!("Video again, {:#?}", v);
Ok(())
}