activitystreams_types/lib.rs
1/*
2 * This file is part of ActivityStreams Types.
3 *
4 * Copyright © 2018 Riley Trautman
5 *
6 * ActivityStreams Types is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ActivityStreams Types is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with ActivityStreams Types. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20//! ActivityStreams Types
21//!
22//! This crate defines the base set of types from the Activity Streams specification.
23//!
24//! ## Example Usage
25//! ```rust
26//! use activitystreams_types::{context, link::Mention};
27//!
28//! fn run() -> Result<(), anyhow::Error> {
29//! /// A Mention is the only predefined Link type in the Activity Streams spec
30//! let mut mention = Mention::default();
31//! mention.link_props.set_context_object(context())?;
32//!
33//! let mention_string = serde_json::to_string(&mention)?;
34//!
35//! let mention: Mention = serde_json::from_str(&mention_string)?;
36//!
37//! Ok(())
38//! }
39//! #
40//! # fn main() {
41//! # run().unwrap();
42//! # }
43//! ```
44
45use serde_derive::{Deserialize, Serialize};
46
47/// Define a simple wrapper around a string for this crate's main Context type
48#[derive(Clone, Debug, Deserialize, Serialize)]
49pub struct ContextObject(pub String);
50
51impl activitystreams_traits::Object for ContextObject {}
52
53/// The context associated with all of the Activity Streams types defined in the crate.
54pub fn context() -> ContextObject {
55 ContextObject("https://www.w3.org/ns/activitystreams".to_owned())
56}
57
58pub mod activity;
59pub mod actor;
60pub mod collection;
61mod custom_props;
62pub mod link;
63pub mod object;
64
65pub use self::custom_props::{CustomLink, CustomObject};