Skip to main content

tickertape/
lib.rs

1//! tickertape: a local, append-only event journal backed by memory-mapped segment files.
2//!
3//! One [`Writer`] process appends records; any number of [`Reader`]s, in the same or other processes on the same
4//! host, follow the journal live or replay it from any sequence number. Records are opaque payload bytes with a
5//! sequence number, a caller-defined schema id and two caller-supplied timestamps.
6//!
7//! - The byte layout is specified in `docs/format.md` in the repository, and mirrored by the [`mod@format`] module.
8//! - What survives a process crash or power loss is specified in `docs/crash-contract.md`. In short: a record is
9//!   *visible* to readers, and survives the writer process dying, as soon as [`Writer::append`] returns; it is
10//!   *durable* only after a later [`Writer::checkpoint`] returns, or after a background checkpoint started with
11//!   [`Writer::request_checkpoint`] has finished.
12//!
13//! ```no_run
14//! use tickertape::{NewRecord, Reader, ReaderConfig, Writer, WriterConfig};
15//!
16//! # fn main() -> tickertape::Result<()> {
17//! let mut writer = Writer::open("/tmp/journal", WriterConfig::default())?;
18//! let seq = writer.append(&NewRecord {
19//!     schema_id: 1,
20//!     venue_ts_ns: 0,
21//!     local_ts_ns: tickertape::clock::realtime_ns(),
22//!     payload: b"hello",
23//! })?;
24//! writer.checkpoint()?; // make it durable, not only visible
25//!
26//! let mut reader = Reader::open("/tmp/journal", ReaderConfig::default())?;
27//! reader.seek(seq)?;
28//! if let Some(record) = reader.try_next()? {
29//!     assert_eq!(record.payload, b"hello");
30//! }
31//! # Ok(())
32//! # }
33//! ```
34
35#![deny(unsafe_op_in_unsafe_fn)]
36#![warn(missing_docs)]
37
38#[cfg(not(target_endian = "little"))]
39compile_error!(
40    "tickertape's on-disk format is little-endian and only little-endian targets are supported"
41);
42
43#[cfg(not(unix))]
44compile_error!("tickertape supports Unix (Linux and macOS) only");
45
46mod affinity;
47mod checkpoint;
48pub mod clock;
49mod config;
50mod crc;
51mod error;
52#[cfg(feature = "fault-injection")]
53#[doc(hidden)]
54pub mod fault;
55#[cfg(not(feature = "fault-injection"))]
56mod fault;
57pub mod format;
58pub mod inspect;
59mod journal;
60mod mmap;
61mod notify;
62mod prefault;
63#[cfg(all(test, loom))]
64mod protocol_model;
65mod reader;
66mod record;
67pub mod retention;
68// Hidden: not covered by the compatibility promise (docs/compatibility.md → Rust API). One value of each error and
69// recovery variant, for the tests of the C ABI and the Python bindings.
70#[doc(hidden)]
71pub mod samples;
72pub mod status;
73mod writeback;
74mod writer;
75
76pub use config::{Backoff, HelperCpus, ReaderConfig, RecoveryPolicy, WriterConfig};
77pub use error::{CorruptReason, Error, Result};
78pub use reader::{Reader, Records};
79pub use record::{NewRecord, OwnedRecord, Record};
80pub use writer::{BatchError, CheckpointProgress, RecoveryAction, RecoveryReport, Writer};
81
82/// The version of this crate, as set in `Cargo.toml`.
83pub const VERSION: &str = env!("CARGO_PKG_VERSION");
84
85#[cfg(test)]
86mod tests {
87    #[test]
88    fn version_is_set() {
89        assert!(!super::VERSION.is_empty());
90    }
91}