mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-12 20:57:26 +08:00
Implement custom fmt::Debug for some prost_build generated structs
Currently implemented for: 1. common.Ipv4Addr 2. common.Ipv6Addr 3. common.UUID
This commit is contained in:
@@ -170,7 +170,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.type_attribute("common.RpcDescriptor", "#[derive(Hash, Eq)]")
|
.type_attribute("common.RpcDescriptor", "#[derive(Hash, Eq)]")
|
||||||
.field_attribute(".web.NetworkConfig", "#[serde(default)]")
|
.field_attribute(".web.NetworkConfig", "#[serde(default)]")
|
||||||
.service_generator(Box::new(rpc_build::ServiceGenerator::new()))
|
.service_generator(Box::new(rpc_build::ServiceGenerator::new()))
|
||||||
.btree_map(["."]);
|
.btree_map(["."])
|
||||||
|
.skip_debug(&[".common.Ipv4Addr", ".common.Ipv6Addr", ".common.UUID"]);
|
||||||
|
|
||||||
config.compile_protos(&proto_files, &["src/proto/"])?;
|
config.compile_protos(&proto_files, &["src/proto/"])?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{fmt::Display, str::FromStr};
|
use std::{fmt, str::FromStr};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|
||||||
@@ -33,8 +33,14 @@ impl From<String> for Uuid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Uuid {
|
impl fmt::Display for Uuid {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}", uuid::Uuid::from(self.clone()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Uuid {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}", uuid::Uuid::from(self.clone()))
|
write!(f, "{}", uuid::Uuid::from(self.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,8 +115,8 @@ impl From<Ipv4Inet> for cidr::Ipv4Inet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Ipv4Inet {
|
impl fmt::Display for Ipv4Inet {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}", cidr::Ipv4Inet::from(self.clone()))
|
write!(f, "{}", cidr::Ipv4Inet::from(self.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,8 +155,8 @@ impl FromStr for Url {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Url {
|
impl fmt::Display for Url {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}", self.url)
|
write!(f, "{}", self.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,3 +224,17 @@ impl TryFrom<CompressorAlgo> for CompressionAlgoPb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Ipv4Addr {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let std_ipv4_addr = std::net::Ipv4Addr::from(self.clone());
|
||||||
|
write!(f, "{}", std_ipv4_addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Ipv6Addr {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let std_ipv6_addr = std::net::Ipv6Addr::from(self.clone());
|
||||||
|
write!(f, "{}", std_ipv6_addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user