Skip to main content

lace_tokio/
lib.rs

1//! Tokio Lace runtime for async Lace applications.
2//!
3//! Most applications use [`Lace`] to open memory/filesystem stores, adopt
4//! host-established ILTP transports, build reusable templates with [`spec!`], create
5//! validated [`Record`] values with [`record!`] or `new_record`, and then call
6//! the standalone porcelain functions:
7//! [`list`], [`get`], [`store`], [`for_each`], [`open_interlace`], or
8//! [`bounded_interlace`].
9//!
10//! A [`LaceHandle`] identifies a reusable local participant; a [`LocalPeer`]
11//! adds its own policy operand. A move-only
12//! [`ConnectedPeer`] adopts host-established ILTP IO with an explicit
13//! carrier role.
14//!
15//! Tokio owns sockets, async waiting, typed stream buffering, and task lifecycle.
16//! Core interlace machines remain sans-IO and see only typed semantic messages;
17//! synchronous policy-neutral support stores may live under `runtime_support`.
18
19#[cfg(test)]
20use std::sync::atomic::{AtomicU64, Ordering};
21use std::sync::{Arc, Mutex};
22
23#[cfg(feature = "compiler")]
24pub use lace_compiler::{
25    CompilationError, CompilationErrorKind, CompilationLimits, compile, compile_with_limits,
26};
27use lace_sans_io::core::*;
28pub use lace_sans_io::core::{ChannelBinding, ErrorCategory, PeerProofAssurance, SessionOperand};
29pub use lace_sans_io::logic::{
30    FieldExclusion, InterlaceModule, PreparationError, prepare_facet_constraints,
31};
32use lace_sans_io::runtime_support::in_memory_store::InMemoryStore;
33pub use lace_sans_io::runtime_values::{
34    BoundedInterlaceOutcome, ConnectedPeerOptions, Error, GetOutcome, InterlaceEvent,
35    InterlaceOperationOptions, ListOutcome, OpenBoundary, OpenBoundaryOutcome, OpenEvent,
36    ParticipantPosition, StoreOutcome, StoreRecordDisposition, StoreRecordResult, Terminal,
37    TimeoutPhase,
38};
39pub use policy::IntoPolicy;
40
41/// Stable record creation, parsing, and hash APIs re-exported for runtime users.
42///
43/// Creating record bytes through these helpers does not persist them in a Lace;
44/// store ids and record-fact visibility still go through store-backed runtime
45/// operations such as `store` or `Lace::memory` construction.
46pub mod records {
47    pub use lace_sans_io::records::{
48        BySecret, ByValue, FieldOccurrence, IntoRecordBatch, Record, RecordCreateError,
49        RecordError, RecordHash, RecordKind, RecordMetadata, RecordReadError, RecordSpec,
50        generate_by_secret, new_record,
51    };
52    pub use lace_sans_io::{record, spec};
53}
54
55pub use lace_sans_io::{record, spec};
56pub use records::{
57    BySecret, ByValue, FieldOccurrence, IntoRecordBatch, Record, RecordCreateError, RecordHash,
58    RecordKind, RecordSpec, generate_by_secret, new_record,
59};
60use tokio::sync::watch;
61
62/// App-facing types commonly used with the Tokio runtime.
63pub mod types {
64    pub use crate::{
65        BoundedInterlaceOutcome, ErrorCategory, InterlaceEvent, InterlaceOperationOptions,
66        OpenBoundary, OpenBoundaryOutcome, ParticipantPosition, Terminal, TimeoutPhase,
67    };
68    pub use crate::{InterlaceModule, IntoPolicy};
69    pub use lace_sans_io::core::{
70        ChannelBinding, CloseReason, InterlaceResourceLimits, PeerProofAssurance, SessionOperand,
71    };
72    pub use lace_sans_io::iltp::PortText;
73}
74
75/// Convenient imports for ordinary Tokio Lace applications.
76pub mod prelude {
77    pub use crate::types::{
78        BoundedInterlaceOutcome, CloseReason, ErrorCategory, InterlaceEvent, InterlaceModule,
79        InterlaceResourceLimits, IntoPolicy, OpenBoundary, OpenBoundaryOutcome,
80        ParticipantPosition, Terminal, TimeoutPhase,
81    };
82    pub use crate::{
83        BoundedInterlace, BySecret, ByValue, CarrierRole, ChannelBinding, ConnectedPeer,
84        ConnectedPeerOptions, Error, FieldOccurrence, ForEachStream, GetOutcome,
85        InterlaceOperationOptions, IntoRecordBatch, Lace, LaceHandle, ListOutcome, LocalPeer,
86        OpenEvent, OpenInterlace, Participant, PeerProofAssurance, PortText, PortableStoreFormat,
87        Record, RecordCreateError, RecordHash, RecordKind, RecordSpec, RecordStream, Result,
88        SessionOperand, StoreOutcome, StoreRecordDisposition, StoreRecordResult, StoreStream,
89        StreamEncoding, bounded_interlace, bounded_interlace_with_options, for_each,
90        for_each_with_options, generate_by_secret, get, get_with_options, list, list_with_options,
91        new_record, open_interlace, open_interlace_with_options, open_interlace_with_selector,
92        read_record_stream, record, spec, store, store_stream, store_stream_with_options,
93        store_with_options,
94    };
95}
96
97/// Result type used by the Tokio runtime.
98pub type Result<T> = std::result::Result<T, Error>;
99
100#[cfg(all(target_pointer_width = "64", any(unix, windows)))]
101mod compaction;
102mod driver;
103mod io;
104mod operations;
105pub mod policy;
106mod record_stream;
107mod runtime;
108
109#[cfg(feature = "lmdb")]
110pub use compaction::compact_lmdb;
111#[cfg(all(target_pointer_width = "64", any(unix, windows)))]
112pub use compaction::{ArenaRelease, CompactionReport, compact_filesystem};
113pub use io::{IoSettings, configure_io};
114pub use lace_sans_io::core::CarrierRole;
115pub use lace_sans_io::iltp::{PortText, StreamEncoding};
116pub use lace_sans_io::runtime_support::portable_file_store::PortableStoreFormat;
117pub use operations::{
118    BoundedInterlace, ForEachStream, OpenInterlace, StoreStream, bounded_interlace,
119    bounded_interlace_with_options, for_each, for_each_with_options, get, get_with_options, list,
120    list_with_options, open_interlace, open_interlace_with_options, open_interlace_with_selector,
121    store, store_stream, store_stream_with_options, store_with_options,
122};
123pub use record_stream::{RecordStream, read_record_stream};
124pub use runtime::{ConnectedPeer, Lace, LaceHandle, LocalPeer, Participant};
125
126mod transport;
127
128#[cfg(test)]
129mod tests;