activitystreams/examples/basic.rs

32 lines
847 B
Rust
Raw Normal View History

2020-03-19 01:23:45 +00:00
use activitystreams::{
2022-01-11 17:58:16 +00:00
context, iri,
2020-07-25 22:11:42 +00:00
object::{ApObject, Video},
prelude::*,
2020-03-19 01:23:45 +00:00
};
2022-01-11 17:58:16 +00:00
use time::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())
2022-01-11 17:58:16 +00:00
.set_id(iri!("https://example.com/@example/lions"))
2020-07-25 22:11:42 +00:00
.set_media_type("video/webm".parse()?)
2022-01-11 17:58:16 +00:00
.set_url(iri!("https://example.com/@example/lions/video.webm"))
2020-07-25 22:11:42 +00:00
.set_summary("A cool video".to_owned())
.set_duration(Duration::minutes(4) + Duration::seconds(20))
2022-01-11 17:58:16 +00:00
.set_shares(iri!("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(())
}