libipld/
store.rs

1//! Store traits.
2//!
3//! ## Aliases
4//! An alias is a named root of a dag. When a root is aliased, none of the leaves of the dag
5//! pointed to by the root will be collected by gc. However, a root being aliased does not
6//! mean that the dag must be complete.
7//!
8//! ## Temporary pin
9//! A temporary pin is an unnamed set of roots of a dag, that is just for the purpose of protecting
10//! blocks from gc while a large tree is constructed. While an alias maps a single name to a
11//! single root, a temporary alias can be assigned to an arbitrary number of blocks before the
12//! dag is finished.
13//!
14//! ## Garbage collection (GC)
15//! GC refers to the process of removing unaliased blocks. When it runs is implementation defined.
16//! However it is intended to run only when the configured size is exceeded at when it will start
17//! incrementally deleting unaliased blocks until the size target is no longer exceeded. It is
18//! implementation defined in which order unaliased blocks get removed.
19use crate::codec::Codec;
20use crate::multihash::MultihashDigest;
21
22/// The store parameters.
23pub trait StoreParams: std::fmt::Debug + Clone + Send + Sync + Unpin + 'static {
24    /// The multihash type of the store.
25    type Hashes: MultihashDigest<64>;
26    /// The codec type of the store.
27    type Codecs: Codec;
28    /// The maximum block size supported by the store.
29    const MAX_BLOCK_SIZE: usize;
30}
31
32/// Default store parameters.
33#[derive(Clone, Debug, Default)]
34pub struct DefaultParams;
35
36impl StoreParams for DefaultParams {
37    const MAX_BLOCK_SIZE: usize = 1_048_576;
38    type Codecs = crate::IpldCodec;
39    type Hashes = crate::multihash::Code;
40}