From 09b5c0a4c8aa5840846a4e737ba1c2c2ad335e8b Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 23 Jan 2026 10:29:55 -0300 Subject: [PATCH 1/4] make encode feature public available --- src/encode.rs | 12 ++++++------ src/lib.rs | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/encode.rs b/src/encode.rs index 48cdde2..7bad62e 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -4,19 +4,19 @@ use crate::leb128; pub(crate) type IntDecodeError = leb128::DecodeError; -/// TODO: docs -pub(crate) trait Encode { - /// TODO: docs +/// Trait for encoding values into a byte buffer. +pub trait Encode { + /// Encodes this value into the provided buffer. fn encode(&self, buf: &mut Vec); } -/// TODO: docs -pub(crate) trait Decode { +/// Trait for decoding values from a byte slice. +pub trait Decode { type Value: Sized; type Error: Display; - /// TODO: docs + /// Decodes a value from the beginning of the buffer. fn decode(buf: &[u8]) -> Result<(Self::Value, &[u8]), Self::Error>; } diff --git a/src/lib.rs b/src/lib.rs index 31bafc0..1d83e1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,6 +151,10 @@ use backlog::Backlog; pub use backlog::{BackloggedDeletions, BackloggedInsertions}; pub use deletion::Deletion; #[cfg(feature = "encode")] +pub use encode::Decode; +#[cfg(feature = "encode")] +pub use encode::Encode; +#[cfg(feature = "encode")] pub use encoded_replica::{DecodeError, EncodedReplica}; use gtree::{Gtree, LeafIdx}; pub use insertion::Insertion; From 8b274b7ab0da109725c756f5e782ffbdc7830271 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 23 Jan 2026 10:55:43 -0300 Subject: [PATCH 2/4] lint encode export --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1d83e1d..9786392 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,9 +151,7 @@ use backlog::Backlog; pub use backlog::{BackloggedDeletions, BackloggedInsertions}; pub use deletion::Deletion; #[cfg(feature = "encode")] -pub use encode::Decode; -#[cfg(feature = "encode")] -pub use encode::Encode; +pub use encode::{Decode, Encode}; #[cfg(feature = "encode")] pub use encoded_replica::{DecodeError, EncodedReplica}; use gtree::{Gtree, LeafIdx}; From a2bfd1288db83606630ac76ad11c226abbd6f4d9 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 23 Jan 2026 11:01:29 -0300 Subject: [PATCH 3/4] tweak comments --- src/encode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/encode.rs b/src/encode.rs index 7bad62e..fd2f38b 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -16,7 +16,7 @@ pub trait Decode { type Error: Display; - /// Decodes a value from the beginning of the buffer. + /// Decodes a buffer into a value. fn decode(buf: &[u8]) -> Result<(Self::Value, &[u8]), Self::Error>; } From 74c0354f188a3984ef7dd3ba8ce06d85f3118338 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 23 Jan 2026 11:30:50 -0300 Subject: [PATCH 4/4] make structs and enum as public available --- src/anchor.rs | 4 ++-- src/backlog.rs | 4 ++-- src/deletion.rs | 6 +++--- src/encode.rs | 19 +++++++++++++------ src/gtree.rs | 10 +++++----- src/insertion.rs | 2 +- src/leb128.rs | 2 +- src/replica.rs | 2 +- src/run_indices.rs | 12 ++++++------ src/run_tree.rs | 12 ++++-------- src/utils.rs | 2 +- src/version_map.rs | 2 +- traces/src/concurrent.rs | 2 +- 13 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/anchor.rs b/src/anchor.rs index 2096896..1b311d7 100644 --- a/src/anchor.rs +++ b/src/anchor.rs @@ -87,7 +87,7 @@ impl core::ops::Not for AnchorBias { /// TODO: docs #[derive(Copy, Clone, PartialEq, Eq)] -pub(crate) struct InnerAnchor { +pub struct InnerAnchor { /// TODO: docs replica_id: ReplicaId, @@ -164,7 +164,7 @@ mod encode { } } - pub(crate) enum AnchorDecodeError { + pub enum AnchorDecodeError { Bool(BoolDecodeError), Int(IntDecodeError), } diff --git a/src/backlog.rs b/src/backlog.rs index fad467c..76461ab 100644 --- a/src/backlog.rs +++ b/src/backlog.rs @@ -8,7 +8,7 @@ use crate::*; /// /// See [`Replica::backlogged`] for more information. #[derive(Debug, Clone, Default, PartialEq)] -pub(crate) struct Backlog { +pub struct Backlog { insertions: ReplicaIdMap, deletions: ReplicaIdMap, } @@ -339,7 +339,7 @@ pub(crate) mod encode { } } - pub(crate) enum BacklogDecodeError { + pub enum BacklogDecodeError { Int(IntDecodeError), VersionMap(BaseMapDecodeError), } diff --git a/src/deletion.rs b/src/deletion.rs index fe166e9..b5fad03 100644 --- a/src/deletion.rs +++ b/src/deletion.rs @@ -107,7 +107,7 @@ mod encode { } } - pub(crate) enum DeletionDecodeError { + pub enum DeletionDecodeError { Anchors(AnchorsDecodeError), Int(IntDecodeError), VersionMap(BaseMapDecodeError), @@ -208,7 +208,7 @@ mod encode { } } - pub(crate) enum AnchorsDecodeError { + pub enum AnchorsDecodeError { Int(IntDecodeError), Flag(AnchorsFlagDecodeError), } @@ -320,7 +320,7 @@ mod encode { } } - pub(crate) enum AnchorsFlagDecodeError { + pub enum AnchorsFlagDecodeError { EmptyBuffer, InvalidByte(u8), } diff --git a/src/encode.rs b/src/encode.rs index fd2f38b..ba6ba50 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -2,7 +2,7 @@ use core::fmt::Display; use crate::leb128; -pub(crate) type IntDecodeError = leb128::DecodeError; +pub type IntDecodeError = leb128::DecodeError; /// Trait for encoding values into a byte buffer. pub trait Encode { @@ -12,23 +12,30 @@ pub trait Encode { /// Trait for decoding values from a byte slice. pub trait Decode { + /// The type of value produced by decoding. type Value: Sized; - + /// The error type returned when decoding fails. type Error: Display; /// Decodes a buffer into a value. fn decode(buf: &[u8]) -> Result<(Self::Value, &[u8]), Self::Error>; } -/// TODO: docs -pub(crate) trait DecodeWithCtx { +/// Trait for decoding values that require additional context. +/// +/// This is similar to [`Decode`], but allows passing mutable context that +/// can be used during the decoding process. +pub trait DecodeWithCtx { + /// The type of value produced by decoding. type Value: Sized; + /// The error type returned when decoding fails. type Error: Display; + /// The context type required for decodin type Ctx; - /// TODO: docs + /// Decodes a value from the buffer using the provided context. fn decode<'buf>( buf: &'buf [u8], ctx: &mut Self::Ctx, @@ -59,7 +66,7 @@ impl Decode for bool { } } -pub(crate) enum BoolDecodeError { +pub enum BoolDecodeError { EmptyBuffer, InvalidByte(u8), } diff --git a/src/gtree.rs b/src/gtree.rs index 919eb20..d91faec 100644 --- a/src/gtree.rs +++ b/src/gtree.rs @@ -100,7 +100,7 @@ const _NODE_IDX_LAYOUT_CHECK: usize = { /// /// TODO: finish describing the data structure. #[derive(Clone)] -pub(crate) struct Gtree { +pub struct Gtree { /// The internal nodes of the Gtree. /// /// The order in which the inodes appear in this vector doesn't have any @@ -129,7 +129,7 @@ pub(crate) struct Gtree { /// It can be passed to [`Gtree::inode()`] and [`Gtree::inode_mut()`] to /// get access to the inode. #[derive(Clone, Copy, PartialEq, Eq)] -pub(crate) struct InodeIdx(usize); +pub struct InodeIdx(usize); impl InodeIdx { /// Returns a "dangling" index which doesn't point to any inode of the @@ -2472,7 +2472,7 @@ type ChildIdx = usize; /// An internal node of the Gtree. #[derive(Clone)] -pub(crate) struct Inode { +pub struct Inode { /// The total len of this node, which is the sum of the lengths of /// all of its children. tot_len: Length, @@ -2809,7 +2809,7 @@ impl Inode { /// A leaf node of the Gtree. #[derive(Debug, Clone, PartialEq)] -pub(crate) struct Lnode { +pub struct Lnode { /// The value of this leaf node. value: Leaf, @@ -3686,7 +3686,7 @@ pub(crate) mod encode { } } - pub(crate) enum InodeDecodeError { + pub enum InodeDecodeError { Bool(BoolDecodeError), Int(IntDecodeError), } diff --git a/src/insertion.rs b/src/insertion.rs index 21e0bca..e9a0df1 100644 --- a/src/insertion.rs +++ b/src/insertion.rs @@ -147,7 +147,7 @@ mod encode { } } - pub(crate) enum InsertionDecodeError { + pub enum InsertionDecodeError { Int(IntDecodeError), Run(BoolDecodeError), } diff --git a/src/leb128.rs b/src/leb128.rs index 5d6314a..c08d2da 100644 --- a/src/leb128.rs +++ b/src/leb128.rs @@ -54,7 +54,7 @@ decode!(decode_u32, u32); decode!(decode_u64, u64); #[cfg_attr(test, derive(Debug, PartialEq))] -pub(crate) enum DecodeError { +pub enum DecodeError { NotEnoughBytes, #[cfg_attr( any(target_arch = "x86", target_arch = "x86_64"), diff --git a/src/replica.rs b/src/replica.rs index 2b93869..fb42d8d 100644 --- a/src/replica.rs +++ b/src/replica.rs @@ -1071,7 +1071,7 @@ mod encode { } } - pub(crate) enum ReplicaDecodeError { + pub enum ReplicaDecodeError { Backlog(BacklogDecodeError), DeletionMap(BaseMapDecodeError), Int(IntDecodeError), diff --git a/src/run_indices.rs b/src/run_indices.rs index 49b03c1..dea63a2 100644 --- a/src/run_indices.rs +++ b/src/run_indices.rs @@ -6,7 +6,7 @@ use crate::*; /// A data structure used when merging remote edits to efficiently map /// an [`Anchor`] to the [`LeafIdx`] of the [`EditRun`] that contains it. #[derive(Clone, Default, PartialEq)] -pub(crate) struct RunIndices { +pub struct RunIndices { map: ReplicaIdMap, } @@ -74,7 +74,7 @@ impl RunIndices { /// Contains the [`LeafIdx`]s of all the [`EditRun`]s that have been inserted /// by a given `Replica`. #[derive(Clone, Default, PartialEq)] -pub(crate) struct ReplicaIndices { +pub struct ReplicaIndices { /// The [`Fragments`] are stored sequentially and in order of insertion. /// /// When a new [`EditRun`] is created we append a new [`Fragments`] to the @@ -233,7 +233,7 @@ mod fragments { /// The `Fragment`s that an insertion run has been fragmented into. #[derive(Clone, PartialEq)] - pub(crate) enum Fragments { + pub enum Fragments { /// The first `INLINE` fragments are stored inline to avoid /// allocating a `Gtree` for runs that are not heavily fragmented. Array(Array), @@ -477,7 +477,7 @@ mod fragments { } } - pub(crate) enum FragmentsIter<'a, const N: usize> { + pub enum FragmentsIter<'a, const N: usize> { Array(core::slice::Iter<'a, Fragment>), Gtree(crate::gtree::Leaves<'a, N, Fragment>), } @@ -498,7 +498,7 @@ mod fragments { } #[derive(Clone, PartialEq)] - pub(crate) struct Array { + pub struct Array { fragments: [Fragment; N], /// The number of non-null `Fragment`s in the array. @@ -633,7 +633,7 @@ mod fragments { /// The length and [`LeafIdx`] of a fragment of a single insertion run. #[derive(Copy, Clone, PartialEq)] -pub(crate) struct Fragment { +pub struct Fragment { len: Length, idx: LeafIdx, } diff --git a/src/run_tree.rs b/src/run_tree.rs index e7ce43f..ff9fcdb 100644 --- a/src/run_tree.rs +++ b/src/run_tree.rs @@ -9,7 +9,7 @@ const RUN_TREE_ARITY: usize = 32; type Gtree = crate::Gtree; #[derive(Clone, Debug, PartialEq)] -pub(crate) struct RunTree { +pub struct RunTree { /// The tree of runs. gtree: Gtree, @@ -858,7 +858,7 @@ impl RunTree { /// TODO: docs #[derive(Clone, PartialEq, Eq)] -pub(crate) struct EditRun { +pub struct EditRun { /// TODO: docs text: Text, @@ -1135,11 +1135,7 @@ pub(crate) mod encode { use super::*; use crate::encode::{ - BoolDecodeError, - Decode, - DecodeWithCtx, - Encode, - IntDecodeError, + BoolDecodeError, Decode, DecodeWithCtx, Encode, IntDecodeError, }; use crate::gtree::{encode::InodeDecodeError, Inode, InodeIdx, Lnode}; use crate::run_indices::{Fragment, Fragments, ReplicaIndices}; @@ -1181,7 +1177,7 @@ pub(crate) mod encode { } } - pub(crate) enum RunTreeDecodeError { + pub enum RunTreeDecodeError { Bool(BoolDecodeError), Inode(InodeDecodeError), Int(IntDecodeError), diff --git a/src/utils.rs b/src/utils.rs index 8c3be08..ec9dadb 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,7 +4,7 @@ use core::ops::{Add, Range as StdRange, RangeBounds, Sub}; use crate::Length; #[derive(Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) struct Range { +pub struct Range { pub start: T, pub end: T, } diff --git a/src/version_map.rs b/src/version_map.rs index 9b68c17..7baed08 100644 --- a/src/version_map.rs +++ b/src/version_map.rs @@ -181,7 +181,7 @@ pub(crate) mod encode { } } - pub(crate) enum BaseMapDecodeError { + pub enum BaseMapDecodeError { Key(IntDecodeError), Value(T::Error), } diff --git a/traces/src/concurrent.rs b/traces/src/concurrent.rs index 6732038..2d645e3 100644 --- a/traces/src/concurrent.rs +++ b/traces/src/concurrent.rs @@ -11,7 +11,7 @@ type TxnIdx = usize; #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -pub(crate) struct ConcurrentDataSet { +pub struct ConcurrentDataSet { kind: String, end_content: String, num_agents: usize,