activityrust/
lib.rs

1//!# ActivityRust
2//!
3//!## What is ActivityRust ?
4//!ActivityRust is a crate that allows a user to manage the structures used by common implementations of the ActivityPub protocol. In order to do so, it tries to be compilant with:
5//! * The ActivityStream Vocabulary, as defined [here](https://www.w3.org/TR/activitystreams-vocabulary/)
6//! * The ActivityPub extensions, as defined [here](https://www.w3.org/TR/activitypub/)
7//! * Parts of the W3ID Security extension, as defined [here](https://w3id.org/)
8//! * The WebFinger schema
9//!ActivityRust allows creation and edition of these structures, but can also serialize and deserialize them to json.
10//!
11//!## How to use ActivityRust ?
12//!
13//!### Creating an ActivityStream entity
14//!
15//!```rust
16//!extern crate activityrust;
17//!// Import the required traits
18//!use activityrust::traits::properties::*;
19//!
20//!use activityrust::entities::actortypes::ActivityStreamPerson;
21//!use url::Url;
22//!
23//!fn main() {
24//!
25//!  let mut activity = ActivityStreamPerson::create();
26//!  let activity_url = Url::parse("http://test.test").unwrap();
27//!  activity.set_id(activity_url);
28//!
29//!}
30//!```
31//!As ActivityStream, ActivityRust supports setting null values for properties. In practice, it means that you can do this:
32//!```rust
33//!  activity.set_summary::<String, Option<String>>(None);
34//!```
35//!
36//!### Deserializing/Serializing an ActivityStream entity
37//!
38//! ActivityRust supports the `serde` module, and all entities can be deserialized to their proper types and serialized to JSON.
39//!
40//!## Compatibility
41//!
42//!ActivityRust is tested against all the examples in `ActivityStream` and in `ActivityPub`, except examples `102` and `149`.
43//!Indeed, example 102 uses multiple object types, that we don't support and example 149 because the content of the example does not match the specification
44//!
45//!We do have the following limitations:
46//!  * The `type` property can only have a single value
47//!  * The W3ID Security extension is only partially supported
48#[macro_use]
49pub mod traits;
50pub mod content;
51pub mod entities;
52
53pub trait MaybeOptional<T> {
54    fn get_optional(self) -> Option<T>;
55}
56
57impl<T> MaybeOptional<T> for T {
58    fn get_optional(self) -> Option<T> {
59        Some(self)
60    }
61}
62
63impl<T> MaybeOptional<T> for Option<T> {
64    fn get_optional(self) -> Option<T> {
65        self
66    }
67}