Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -164,7 +164,7 @@ mod encode {
}
}

pub(crate) enum AnchorDecodeError {
pub enum AnchorDecodeError {
Bool(BoolDecodeError),
Int(IntDecodeError),
}
Expand Down
4 changes: 2 additions & 2 deletions src/backlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InsertionsBacklog>,
deletions: ReplicaIdMap<DeletionsBacklog>,
}
Expand Down Expand Up @@ -339,7 +339,7 @@ pub(crate) mod encode {
}
}

pub(crate) enum BacklogDecodeError {
pub enum BacklogDecodeError {
Int(IntDecodeError),
VersionMap(BaseMapDecodeError<Length>),
}
Expand Down
6 changes: 3 additions & 3 deletions src/deletion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ mod encode {
}
}

pub(crate) enum DeletionDecodeError {
pub enum DeletionDecodeError {
Anchors(AnchorsDecodeError),
Int(IntDecodeError),
VersionMap(BaseMapDecodeError<Length>),
Expand Down Expand Up @@ -208,7 +208,7 @@ mod encode {
}
}

pub(crate) enum AnchorsDecodeError {
pub enum AnchorsDecodeError {
Int(IntDecodeError),
Flag(AnchorsFlagDecodeError),
}
Expand Down Expand Up @@ -320,7 +320,7 @@ mod encode {
}
}

pub(crate) enum AnchorsFlagDecodeError {
pub enum AnchorsFlagDecodeError {
EmptyBuffer,
InvalidByte(u8),
}
Expand Down
31 changes: 19 additions & 12 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,40 @@ use core::fmt::Display;

use crate::leb128;

pub(crate) type IntDecodeError = leb128::DecodeError;
pub 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<u8>);
}

/// TODO: docs
pub(crate) trait Decode {
/// 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;

/// TODO: docs
/// 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,
Expand Down Expand Up @@ -59,7 +66,7 @@ impl Decode for bool {
}
}

pub(crate) enum BoolDecodeError {
pub enum BoolDecodeError {
EmptyBuffer,
InvalidByte(u8),
}
Expand Down
10 changes: 5 additions & 5 deletions src/gtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const _NODE_IDX_LAYOUT_CHECK: usize = {
///
/// TODO: finish describing the data structure.
#[derive(Clone)]
pub(crate) struct Gtree<const ARITY: usize, L: Leaf> {
pub struct Gtree<const ARITY: usize, L: Leaf> {
/// The internal nodes of the Gtree.
///
/// The order in which the inodes appear in this vector doesn't have any
Expand Down Expand Up @@ -129,7 +129,7 @@ pub(crate) struct Gtree<const ARITY: usize, L: Leaf> {
/// 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
Expand Down Expand Up @@ -2472,7 +2472,7 @@ type ChildIdx = usize;

/// An internal node of the Gtree.
#[derive(Clone)]
pub(crate) struct Inode<const ARITY: usize, L: Leaf> {
pub struct Inode<const ARITY: usize, L: Leaf> {
/// The total len of this node, which is the sum of the lengths of
/// all of its children.
tot_len: Length,
Expand Down Expand Up @@ -2809,7 +2809,7 @@ impl<const ARITY: usize, L: Leaf> Inode<ARITY, L> {

/// A leaf node of the Gtree.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Lnode<Leaf> {
pub struct Lnode<Leaf> {
/// The value of this leaf node.
value: Leaf,

Expand Down Expand Up @@ -3686,7 +3686,7 @@ pub(crate) mod encode {
}
}

pub(crate) enum InodeDecodeError {
pub enum InodeDecodeError {
Bool(BoolDecodeError),
Int(IntDecodeError),
}
Expand Down
2 changes: 1 addition & 1 deletion src/insertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod encode {
}
}

pub(crate) enum InsertionDecodeError {
pub enum InsertionDecodeError {
Int(IntDecodeError),
Run(BoolDecodeError),
}
Expand Down
2 changes: 1 addition & 1 deletion src/leb128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ use backlog::Backlog;
pub use backlog::{BackloggedDeletions, BackloggedInsertions};
pub use deletion::Deletion;
#[cfg(feature = "encode")]
pub use encode::{Decode, Encode};
#[cfg(feature = "encode")]
pub use encoded_replica::{DecodeError, EncodedReplica};
use gtree::{Gtree, LeafIdx};
pub use insertion::Insertion;
Expand Down
2 changes: 1 addition & 1 deletion src/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ mod encode {
}
}

pub(crate) enum ReplicaDecodeError {
pub enum ReplicaDecodeError {
Backlog(BacklogDecodeError),
DeletionMap(BaseMapDecodeError<DeletionTs>),
Int(IntDecodeError),
Expand Down
12 changes: 6 additions & 6 deletions src/run_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReplicaIndices>,
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -233,7 +233,7 @@ mod fragments {

/// The `Fragment`s that an insertion run has been fragmented into.
#[derive(Clone, PartialEq)]
pub(crate) enum Fragments<const INLINE: usize> {
pub enum Fragments<const INLINE: usize> {
/// The first `INLINE` fragments are stored inline to avoid
/// allocating a `Gtree` for runs that are not heavily fragmented.
Array(Array<INLINE>),
Expand Down Expand Up @@ -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>),
}
Expand All @@ -498,7 +498,7 @@ mod fragments {
}

#[derive(Clone, PartialEq)]
pub(crate) struct Array<const N: usize> {
pub struct Array<const N: usize> {
fragments: [Fragment; N],

/// The number of non-null `Fragment`s in the array.
Expand Down Expand Up @@ -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<EditRun>,
}
Expand Down
12 changes: 4 additions & 8 deletions src/run_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const RUN_TREE_ARITY: usize = 32;
type Gtree = crate::Gtree<RUN_TREE_ARITY, EditRun>;

#[derive(Clone, Debug, PartialEq)]
pub(crate) struct RunTree {
pub struct RunTree {
/// The tree of runs.
gtree: Gtree,

Expand Down Expand Up @@ -858,7 +858,7 @@ impl RunTree {

/// TODO: docs
#[derive(Clone, PartialEq, Eq)]
pub(crate) struct EditRun {
pub struct EditRun {
/// TODO: docs
text: Text,

Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -1181,7 +1177,7 @@ pub(crate) mod encode {
}
}

pub(crate) enum RunTreeDecodeError {
pub enum RunTreeDecodeError {
Bool(BoolDecodeError),
Inode(InodeDecodeError),
Int(IntDecodeError),
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
pub struct Range<T> {
pub start: T,
pub end: T,
}
Expand Down
2 changes: 1 addition & 1 deletion src/version_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub(crate) mod encode {
}
}

pub(crate) enum BaseMapDecodeError<T: Decode> {
pub enum BaseMapDecodeError<T: Decode> {
Key(IntDecodeError),
Value(T::Error),
}
Expand Down
2 changes: 1 addition & 1 deletion traces/src/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down