Skip to main content

willow_data_model/
lib.rs

1#![doc(html_logo_url = "https://willowprotocol.org/assets/willow_emblem_standalone.png")]
2#![cfg_attr(not(feature = "std"), no_std)]
3#![allow(async_fn_in_trait)]
4
5//! # Willow Data Model
6//!
7//! This crate implements the [Willow Data Model](https://willowprotocol.org/specs/data-model/), with plenty of generics to account for all the [data model parameters](https://willowprotocol.org/specs/data-model/index.html#willow_parameters).
8//!
9//! As an application developer, you likely do not need to interact with this crate explicitly — use the [`willow25`](https://crates.io/crates/willow25) crate instead, which wraps this crate with ready-to-use non-generic types. As a library author, this crate *is* the right place. Code library functions against the types and interfaces provided by this crate, so that your code can be used both by other generic code and by code specialised to any particular instantiation of the Willow protocols.
10//!
11//! Many trait methods in this crate have a name starting with `wdm` (Willow Data Model). This naming convention ensures that there are no naming conflicts with methods provided by types which specialise Willow to a particular set of parameters (such as the types of the [`willow25`](https://crates.io/crates/willow25) crate). This is slightly inconvenient when writing generic code, but ensures that application developers who only interact with specialised types  get the smoothest possible development experience.
12//!
13//! Note: we will likely deprecate this crate at some point in the future, and implement Willow25 directly without any generics. See [here](https://worm-blossom.org/#y2026w9a4) for the reasoning. We already stopped providing generic implementations of certain features, for example, the `willow25` crate provides entry storage functionality that has no counterpart in this crate.
14
15pub mod paths;
16
17pub mod entry;
18
19mod timestamp;
20pub use timestamp::Timestamp;
21
22pub mod groupings;
23
24pub mod authorisation;
25
26#[cfg(feature = "dev")]
27pub mod test_parameters;
28
29/// A “prelude” for crates using the `willow_data_model` crate.
30///
31/// This prelude is similar to the standard library’s prelude in that you’ll almost always want to import its entire contents, but unlike the standard library’s prelude you’ll have to do so manually:
32///
33/// `use willow_data_model::prelude::*;`
34///
35/// The prelude may grow over time.
36pub mod prelude {
37    pub use super::authorisation::*;
38    pub use super::entry::{Entry, EntryBuilder, Entrylike, EntrylikeExt};
39    pub use super::groupings::*;
40    pub use super::paths::{
41        Component, InvalidComponentError, OwnedComponent, Path, PathBuilder, PathError,
42        PathFromComponentsError,
43    };
44    pub use super::timestamp::Timestamp;
45    pub use hifitime::prelude::*;
46
47    #[cfg(feature = "dev")]
48    pub use super::test_parameters::*;
49}
50
51/// Checks if a bit of a given byte is flagged at a particular index (with 0 being the most significant bit).
52pub(crate) fn is_bitflagged(byte: u8, index: usize) -> bool {
53    byte & (1u8 << (7 - index)) != 0u8
54}