Skip to content

Commit

Permalink
style: add comments to specify the reason why override Display trait …
Browse files Browse the repository at this point in the history
…instead of Debug trait

Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Mar 12, 2024
1 parent 8068af2 commit 2be11ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 1 addition & 2 deletions crates/xline/src/storage/kvwatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ where
}

/// Watch Event
#[derive(Debug)]
pub(crate) struct WatchEvent {
/// Watch ID
id: WatchId,
Expand All @@ -553,7 +552,7 @@ pub(crate) struct WatchEvent {
compacted: bool,
}

impl std::fmt::Display for WatchEvent {
impl std::fmt::Debug for WatchEvent {
#[allow(clippy::arithmetic_side_effects)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
Expand Down
19 changes: 17 additions & 2 deletions crates/xlineapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ impl Display for AlarmMember {
}
}

/// Since the tokio-rs/prost will automatically derive Debug trait for all the structures it generates, we have to
/// override the Display trait for these requests and responses.
/// FYI: https://github.com/tokio-rs/prost/issues/334
impl Display for PutRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
Expand Down Expand Up @@ -758,22 +761,34 @@ impl Display for RangeRequest {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"RangeRequest {{ key: {:?}, range_end: {:?}, limit: {:?}, revision: {:?}, sort_order: {:?}, sort_target: {:?}, serializable: {:?}, keys_only: {:?}, count_only: {:?}, min_mod_revision: {:?}, max_mod_revision: {:?}, min_create_revision: {:?}, max_create_revision: {:?}, key_only: {:?}, count_only: {:?}, min_mod_revision: {:?}, max_mod_revision: {:?}, min_create_revision: {:?}, max_create_revision: {:?} }}",
"RangeRequest {{ key: {:?}, range_end: {:?}, limit: {:?}, revision: {:?}, sort_order: {:?}, ",
String::from_utf8_lossy(&self.key),
String::from_utf8_lossy(&self.range_end),
self.limit,
self.revision,
self.sort_order,
)?;
write!(
f,
"sort_target: {:?}, serializable: {:?}, keys_only: {:?}, count_only: {:?}, min_mod_revision: {:?}, ",
self.sort_target,
self.serializable,
self.keys_only,
self.count_only,
self.min_mod_revision,
self.min_mod_revision
)?;
write!(
f,
"max_mod_revision: {:?}, min_create_revision: {:?}, max_create_revision: {:?}, key_only: {:?}, count_only: {:?}, ",
self.max_mod_revision,
self.min_create_revision,
self.max_create_revision,
self.keys_only,
self.count_only,
)?;
write!(
f,
"min_mod_revision: {:?}, max_mod_revision: {:?}, min_create_revision: {:?}, max_create_revision: {:?} }}",
self.min_mod_revision,
self.max_mod_revision,
self.min_create_revision,
Expand Down

0 comments on commit 2be11ed

Please sign in to comment.