Skip to main content

actpub_nodeinfo/
lib.rs

1//! `NodeInfo` server metadata protocol for the Fediverse.
2//!
3//! Implements `NodeInfo` [2.0] / [2.1] and [FEP-0151] (`NodeInfo` 2025 edition),
4//! providing both discovery (`/.well-known/nodeinfo`) and schema documents.
5//!
6//! # Example (server)
7//!
8//! ```
9//! use actpub_nodeinfo::{NodeInfo, Software, Usage, UserCount, Protocol, Version};
10//!
11//! let info = NodeInfo::builder(Version::V2_1, Software::new("my-server", "1.0.0"))
12//!     .protocol(Protocol::ActivityPub)
13//!     .open_registrations(true)
14//!     .usage(Usage::new(UserCount::default().with_total(42)))
15//!     .build();
16//!
17//! let json = serde_json::to_string(&info).unwrap();
18//! assert!(json.contains(r#""version":"2.1""#));
19//! ```
20//!
21//! [2.0]: http://nodeinfo.diaspora.software/ns/schema/2.0
22//! [2.1]: http://nodeinfo.diaspora.software/ns/schema/2.1
23//! [FEP-0151]: https://codeberg.org/fediverse/fep/src/branch/main/fep/0151/fep-0151.md
24#![cfg_attr(docsrs, feature(doc_cfg))]
25#![allow(
26    clippy::error_impl_error,
27    reason = "`Error` is the idiomatic name for the crate's top-level error enum, matching the `thiserror` convention used pervasively in the Rust ecosystem"
28)]
29#![cfg_attr(
30    test,
31    allow(
32        clippy::indexing_slicing,
33        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"
34    )
35)]
36
37#[cfg(feature = "client")]
38#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
39mod client;
40mod discovery;
41mod error;
42mod schema;
43
44#[cfg(feature = "client")]
45#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
46pub use self::client::{fetch, fetch_discovery};
47pub use self::discovery::{Discovery, DiscoveryLink, SCHEMA_REL_PREFIX};
48pub use self::error::Error;
49pub use self::schema::{
50    InboundService, NodeInfo, NodeInfoBuilder, OutboundService, Protocol, Services, Software,
51    Usage, UserCount, Version,
52};
53
54/// Crate [`Result`] alias with the default error type set to [`Error`].
55pub type Result<T, E = Error> = core::result::Result<T, E>;
56
57/// The well-known URI path for the `NodeInfo` discovery document.
58pub const WELL_KNOWN_PATH: &str = "/.well-known/nodeinfo";