Skip to main content

actpub_activitystreams/
lib.rs

1//! Activity Streams 2.0 data model and vocabulary.
2//!
3//! This crate provides pure data types (no I/O, no networking) for the W3C
4//! [Activity Streams 2.0 Core] and [Activity Vocabulary] specifications, as
5//! used by the [ActivityPub] protocol.
6//!
7//! # Design
8//!
9//! The types are designed for idiomatic `serde` (de)serialization with
10//! tolerant handling of the JSON-LD variants emitted by real-world Fediverse
11//! implementations such as Mastodon, Pleroma, Lemmy and Misskey.
12//!
13//! Core AS 2.0 types ([`Object`], [`Link`], [`Activity`], [`Collection`]) are
14//! concrete structs with every specification-defined property represented as
15//! `Option<T>` or [`OneOrMany<T>`]. Concrete vocabulary types that add no new
16//! properties (`Note`, `Article`, `Create`, …) share the core structs and are
17//! discriminated by string type constants ([`kind`]), while types that add
18//! new properties (`Question`, `Place`, `Tombstone`) are provided as
19//! dedicated structs that flatten the core object.
20//!
21//! # Interoperability
22//!
23//! Real Fediverse JSON-LD is inconsistent and requires tolerance:
24//!
25//! - Array-typed properties may appear as a single value (handled by
26//!   [`OneOrMany<T>`])
27//! - Object properties may be inlined or appear as plain URL strings (handled
28//!   by [`UrlOr<T>`])
29//! - The [`Public`] audience appears in multiple equivalent forms
30//! - Unknown properties are preserved via flattened extension maps
31//!
32//! [Activity Streams 2.0 Core]: https://www.w3.org/TR/activitystreams-core/
33//! [Activity Vocabulary]: https://www.w3.org/TR/activitystreams-vocabulary/
34//! [ActivityPub]: https://www.w3.org/TR/activitypub/
35#![cfg_attr(docsrs, feature(doc_cfg))]
36#![allow(
37    clippy::error_impl_error,
38    reason = "`Error` is the idiomatic name for the crate's top-level error enum, matching the `thiserror` convention used pervasively in the Rust ecosystem"
39)]
40#![cfg_attr(
41    test,
42    allow(
43        clippy::indexing_slicing,
44        reason = "JSON field indexing via `Value[\"key\"]` is ergonomic inside tests and its panic-on-missing behaviour is the desired failure mode when fixtures are wrong"
45    )
46)]
47
48mod actor;
49mod context;
50mod error;
51mod link;
52mod multikey;
53mod object;
54mod proof;
55mod value;
56
57pub mod kind;
58
59pub use self::actor::{Endpoints, PublicKey};
60pub use self::context::{Context, ContextEntry, WithContext};
61pub use self::error::Error;
62pub use self::link::Link;
63pub use self::multikey::{AssertionMethod, Multikey};
64pub use self::object::{LanguageMap, Object, ObjectRef};
65pub use self::proof::Proof;
66pub use self::value::{HasId, OneOrMany, Public, UrlOr};
67
68/// Crate [`Result`] alias with the default error type set to [`Error`].
69pub type Result<T, E = Error> = core::result::Result<T, E>;