Skip to content

Commit

Permalink
chore: warn missing debug impl (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n authored May 4, 2024
1 parent 659c9c5 commit 456ff12
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/loro-internal/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct SharedArena {
inner: Arc<InnerSharedArena>,
}

#[derive(Debug)]
pub struct StrAllocResult {
/// unicode start
pub start: usize,
Expand Down
3 changes: 2 additions & 1 deletion crates/loro-internal/src/configure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use crate::container::richtext::config::{StyleConfig, StyleConfigMap};

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Configure {
pub(crate) text_style_config: Arc<RwLock<StyleConfigMap>>,
record_timestamp: Arc<AtomicBool>,
Expand Down Expand Up @@ -43,6 +43,7 @@ impl Configure {
}
}

#[derive(Debug)]
pub struct DefaultRandom;

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions crates/loro-internal/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub use loro_common::ContainerType;

pub use loro_common::ContainerID;

#[derive(Debug)]
pub enum ContainerIdRaw {
Root { name: InternalString },
Normal { id: ID },
Expand Down
3 changes: 2 additions & 1 deletion crates/loro-internal/src/delta/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum DeltaItem<Value, Meta> {
Delete { delete: usize, attributes: Meta },
}

#[derive(PartialEq, Eq)]
#[derive(PartialEq, Debug, Eq)]
pub enum DeltaType {
Retain,
Insert,
Expand Down Expand Up @@ -253,6 +253,7 @@ impl<Value: DeltaValue, M: Meta> DeltaItem<Value, M> {
}
}

#[derive(Debug)]
pub struct DeltaIterator<V, M: Meta> {
// The reversed Vec uses pop() to simulate getting the first element each time
ops: Vec<DeltaItem<V, M>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/loro-internal/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn create_handler(inner: &BasicHandler, id: ContainerID) -> Handler {
}

/// Flatten attributes that allow overlap
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct BasicHandler {
id: ContainerID,
arena: SharedArena,
Expand Down
1 change: 1 addition & 0 deletions crates/loro-internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//!
#![deny(clippy::undocumented_unsafe_blocks)]
#![warn(rustdoc::broken_intra_doc_links)]
#![warn(missing_debug_implementations)]

pub mod arena;
pub mod diff_calc;
Expand Down
10 changes: 10 additions & 0 deletions crates/loro-internal/src/loro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ impl Default for LoroDoc {
}
}

impl std::fmt::Debug for LoroDoc {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LoroDoc")
.field("config", &self.config)
.field("auto_commit", &self.auto_commit)
.field("detached", &self.detached)
.finish()
}
}

impl LoroDoc {
pub fn new() -> Self {
let oplog = OpLog::new();
Expand Down
9 changes: 9 additions & 0 deletions crates/loro-internal/src/obs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ pub struct Observer {
taken_times: AtomicUsize,
}

impl std::fmt::Debug for Observer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Observer")
.field("next_sub_id", &self.next_sub_id)
.field("taken_times", &self.taken_times)
.finish()
}
}

impl Observer {
pub fn new(arena: SharedArena) -> Self {
Self {
Expand Down
12 changes: 9 additions & 3 deletions crates/loro-internal/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use tracing::{info, instrument, trace_span};

use crate::{
configure::{Configure, DefaultRandom, SecureRandomGenerator},
container::{
idx::ContainerIdx, richtext::config::StyleConfigMap, ContainerIdRaw,
},
container::{idx::ContainerIdx, richtext::config::StyleConfigMap, ContainerIdRaw},
cursor::Cursor,
encoding::{StateSnapshotDecodeContext, StateSnapshotEncoder},
event::{Diff, EventTriggerKind, Index, InternalContainerDiff, InternalDiff},
Expand Down Expand Up @@ -71,6 +69,14 @@ pub struct DocState {
event_recorder: EventRecorder,
}

impl std::fmt::Debug for DocState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DocState")
.field("peer", &self.peer)
.finish()
}
}

#[enum_dispatch]
pub(crate) trait ContainerState: Clone {
fn container_idx(&self) -> ContainerIdx;
Expand Down
20 changes: 20 additions & 0 deletions crates/loro-internal/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ pub struct Transaction {
timestamp: Option<Timestamp>,
}

impl std::fmt::Debug for Transaction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Transaction")
.field("peer", &self.peer)
.field("origin", &self.origin)
.field("start_counter", &self.start_counter)
.field("next_counter", &self.next_counter)
.field("start_lamport", &self.start_lamport)
.field("next_lamport", &self.next_lamport)
.field("frontiers", &self.frontiers)
.field("local_ops", &self.local_ops)
.field("event_hints", &self.event_hints)
.field("arena", &self.arena)
.field("finished", &self.finished)
.field("on_commit", &self.on_commit.is_some())
.field("timestamp", &self.timestamp)
.finish()
}
}

/// We can infer local events directly from the local behavior. This enum is used to
/// record them, so that we can avoid recalculate them when we commit the transaction.
///
Expand Down
2 changes: 2 additions & 0 deletions crates/loro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]
use either::Either;
use event::{DiffEvent, Subscriber};
use loro_internal::change::Timestamp;
Expand Down Expand Up @@ -44,6 +45,7 @@ pub use loro_internal::{LoroError, LoroResult, LoroValue, ToJson};

/// `LoroDoc` is the entry for the whole document.
/// When it's dropped, all the associated [`Handler`]s will be invalidated.
#[derive(Debug)]
pub struct LoroDoc {
doc: InnerLoroDoc,
}
Expand Down

0 comments on commit 456ff12

Please sign in to comment.