Skip to content

Commit c891ac6

Browse files
sebastiencsakoptelov
authored andcommitted
Make Debug format more compact for some types
Avoid vertical alignment
1 parent feee4c6 commit c891ac6

File tree

5 files changed

+57
-19
lines changed

5 files changed

+57
-19
lines changed

mina-p2p-messages/src/bigint.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
use serde::{Deserialize, Serialize};
22

3-
#[derive(
4-
Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, derive_more::From, derive_more::Into,
5-
)]
3+
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, derive_more::From, derive_more::Into)]
64
pub struct BigInt(Box<[u8; 32]>);
75

6+
impl std::fmt::Debug for BigInt {
7+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8+
let Self(inner) = self;
9+
// Avoid vertical alignment
10+
f.write_fmt(format_args!("BigInt({:?})", inner))
11+
}
12+
}
13+
814
impl BigInt {
915
#[cfg(feature = "hashing")]
1016
pub fn one() -> Self {

mina-p2p-messages/src/number.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ use std::{fmt::Display, marker::PhantomData, str::FromStr};
33
use serde::{de::Visitor, Deserialize, Serialize};
44

55
#[derive(
6-
Debug,
7-
Clone,
8-
Copy,
9-
Default,
10-
PartialEq,
11-
Eq,
12-
PartialOrd,
13-
Ord,
14-
derive_more::From,
15-
derive_more::Deref,
6+
Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, derive_more::From, derive_more::Deref,
167
)]
178
pub struct Number<T>(pub T);
189

10+
impl<T: std::fmt::Debug> std::fmt::Debug for Number<T> {
11+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12+
let Self(inner) = self;
13+
// Avoid vertical alignment
14+
f.write_fmt(format_args!("Number({:?})", inner))
15+
}
16+
}
17+
1918
pub type Int32 = Number<i32>;
2019
pub type Int64 = Number<i64>;
2120
pub type Float64 = Number<f64>;

mina-p2p-messages/src/string.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ use binprot::Nat0;
22
use serde::{de::Visitor, Deserialize, Serialize};
33

44
/// String of bytes.
5-
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
5+
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
66
pub struct ByteString(Vec<u8>);
77

8+
impl std::fmt::Debug for ByteString {
9+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10+
let Self(inner) = self;
11+
// Avoid vertical alignment
12+
f.write_fmt(format_args!("ByteString({:?})", inner))
13+
}
14+
}
15+
816
impl std::ops::Deref for ByteString {
917
type Target = Vec<u8>;
1018

@@ -117,9 +125,17 @@ impl binprot::BinProtWrite for ByteString {
117125
}
118126

119127
/// Human-readable string.
120-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
128+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
121129
pub struct CharString(Vec<u8>);
122130

131+
impl std::fmt::Debug for CharString {
132+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
133+
let Self(inner) = self;
134+
// Avoid vertical alignment
135+
f.write_fmt(format_args!("CharString({:?})", inner))
136+
}
137+
}
138+
123139
impl CharString {
124140
pub fn to_string_lossy(&self) -> std::string::String {
125141
std::string::String::from_utf8_lossy(&self.0).into_owned()

mina-p2p-messages/src/v2/generated.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ pub struct NonZeroCurvePointUncompressedStableV1 {
795795
///
796796
/// Gid: `125`
797797
/// Location: [src/int64.ml:6:6](https://github.com/MinaProtocol/mina/blob/bfd1009/src/int64.ml#L6)
798-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, BinProtRead, BinProtWrite, Deref)]
798+
#[derive(Clone, PartialEq, Serialize, Deserialize, BinProtRead, BinProtWrite, Deref)]
799799
pub struct UnsignedExtendedUInt64Int64ForVersionTagsStableV1(pub crate::number::Int64);
800800

801801
/// **OCaml name**: `Unsigned_extended.UInt32.Stable.V1`
@@ -806,9 +806,7 @@ pub struct UnsignedExtendedUInt64Int64ForVersionTagsStableV1(pub crate::number::
806806
///
807807
/// Gid: `119`
808808
/// Location: [src/int32.ml:6:6](https://github.com/MinaProtocol/mina/blob/bfd1009/src/int32.ml#L6)
809-
#[derive(
810-
Clone, Debug, PartialEq, Serialize, Deserialize, BinProtRead, BinProtWrite, Deref, Default,
811-
)]
809+
#[derive(Clone, PartialEq, Serialize, Deserialize, BinProtRead, BinProtWrite, Deref, Default)]
812810
pub struct UnsignedExtendedUInt32StableV1(pub crate::number::Int32);
813811

814812
/// **OCaml name**: `Mina_numbers__Nat.Make32.Stable.V1`

mina-p2p-messages/src/v2/manual.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,4 +805,23 @@ impl From<&PicklesProofProofsVerifiedMaxStableV2> for PicklesProofProofsVerified
805805
}
806806
}
807807

808+
impl std::fmt::Debug for super::UnsignedExtendedUInt32StableV1 {
809+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
810+
let Self(inner) = self;
811+
// Avoid vertical alignment
812+
f.write_fmt(format_args!("UnsignedExtendedUInt32StableV1({:?})", inner))
813+
}
814+
}
815+
816+
impl std::fmt::Debug for super::UnsignedExtendedUInt64Int64ForVersionTagsStableV1 {
817+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
818+
let Self(inner) = self;
819+
// Avoid vertical alignment
820+
f.write_fmt(format_args!(
821+
"UnsignedExtendedUInt64Int64ForVersionTagsStableV1({:?})",
822+
inner
823+
))
824+
}
825+
}
826+
808827
pub mod conv;

0 commit comments

Comments
 (0)