hypercore/lib.rs
1#![forbid(
2 unsafe_code,
3 future_incompatible,
4 rust_2018_idioms,
5 rust_2018_compatibility,
6 missing_debug_implementations,
7 missing_docs
8)]
9#![doc(test(attr(deny(warnings))))]
10#![warn(
11 unreachable_pub,
12 redundant_lifetimes,
13 non_local_definitions,
14 clippy::needless_pass_by_value,
15 clippy::needless_pass_by_ref_mut,
16 clippy::enum_glob_use
17)]
18
19//! ## Introduction
20//!
21//! Hypercore is a secure, distributed append-only log. Built for sharing
22//! large datasets and streams of real time data as part of the [Dat] project.
23//! This is a rust port of [the original Javascript version][holepunch-hypercore]
24//! aiming for interoperability with LTS version. The primary way to use this
25//! crate is through the [Hypercore] struct, which can be created using the
26//! [HypercoreBuilder].
27//!
28//! This crate supports WASM with `cargo build --target=wasm32-unknown-unknown`.
29//!
30//! ## Features
31//!
32//! ### `sparse` (default)
33//!
34//! When using disk storage, clearing values may create sparse files. On by default.
35//!
36//! ### `async-std` (default)
37//!
38//! Use the async-std runtime, on by default. Either this or `tokio` is mandatory.
39//!
40//! ### `tokio`
41//!
42//! Use the tokio runtime. Either this or `async_std` is mandatory.
43//!
44//! ### `cache`
45//!
46//! Use a moka cache for merkle tree nodes to speed-up reading.
47//!
48//! ## Example
49//! ```rust
50//! # #[cfg(feature = "tokio")]
51//! # tokio_test::block_on(async {
52//! # example().await;
53//! # });
54//! # #[cfg(feature = "async-std")]
55//! # async_std::task::block_on(async {
56//! # example().await;
57//! # });
58//! # async fn example() {
59//! use hypercore::{HypercoreBuilder, Storage};
60//!
61//! // Create an in-memory hypercore using a builder
62//! let mut hypercore = HypercoreBuilder::new(Storage::new_memory().await.unwrap())
63//! .build()
64//! .await
65//! .unwrap();
66//!
67//! // Append entries to the log
68//! hypercore.append(b"Hello, ").await.unwrap();
69//! hypercore.append(b"world!").await.unwrap();
70//!
71//! // Read entries from the log
72//! assert_eq!(hypercore.get(0).await.unwrap().unwrap(), b"Hello, ");
73//! assert_eq!(hypercore.get(1).await.unwrap().unwrap(), b"world!");
74//! # }
75//! ```
76//!
77//! Find more examples in the [examples] folder.
78//!
79//! [Dat]: https://github.com/datrs
80//! [holepunch-hypercore]: https://github.com/holepunchto/hypercore
81//! [Hypercore]: crate::core::Hypercore
82//! [HypercoreBuilder]: crate::builder::HypercoreBuilder
83//! [examples]: https://github.com/datrs/hypercore/tree/master/examples
84
85pub mod encoding;
86pub mod prelude;
87#[cfg(feature = "replication")]
88pub mod replication;
89
90mod bitfield;
91mod builder;
92mod common;
93mod core;
94mod crypto;
95mod data;
96mod oplog;
97mod storage;
98mod tree;
99
100#[cfg(feature = "cache")]
101pub use crate::builder::CacheOptionsBuilder;
102pub use crate::builder::HypercoreBuilder;
103pub use crate::common::{HypercoreError, Store};
104pub use crate::core::{AppendOutcome, Hypercore, Info};
105pub use crate::crypto::{PartialKeypair, generate_signing_key, sign, verify};
106pub use crate::storage::{Storage, StorageTraits};
107pub use ed25519_dalek::{
108 KEYPAIR_LENGTH, PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, SecretKey, Signature, SigningKey,
109 VerifyingKey,
110};