Skip to content

Commit b0ce0b8

Browse files
committed
chore: impl Debug using Display for Endpoint
`Debug` of `Vec<Endpoint>` will give us nice formatted endpoints. Also, `Display` covers all informations `Endpoint` carried.
1 parent 43062b1 commit b0ce0b8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/endpoint.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use crate::chroot::Chroot;
55
use crate::error::Error;
66
use crate::util::{Ref, ToRef};
77

8-
#[derive(Debug, Clone, PartialEq, Eq)]
8+
#[derive(Clone, PartialEq, Eq)]
99
pub struct Endpoint {
1010
pub host: String,
1111
pub port: u16,
1212
pub tls: bool,
1313
}
1414

15-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
15+
#[derive(Copy, Clone, PartialEq, Eq)]
1616
pub struct EndpointRef<'a> {
1717
pub host: &'a str,
1818
pub port: u16,
@@ -37,6 +37,12 @@ impl Display for Endpoint {
3737
}
3838
}
3939

40+
impl fmt::Debug for Endpoint {
41+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
42+
Display::fmt(self, f)
43+
}
44+
}
45+
4046
impl<'a> From<(&'a str, u16, bool)> for EndpointRef<'a> {
4147
fn from(v: (&'a str, u16, bool)) -> Self {
4248
Self::new(v.0, v.1, v.2)
@@ -50,6 +56,12 @@ impl Display for EndpointRef<'_> {
5056
}
5157
}
5258

59+
impl fmt::Debug for EndpointRef<'_> {
60+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
61+
Display::fmt(self, f)
62+
}
63+
}
64+
5365
impl PartialEq<(&str, u16, bool)> for EndpointRef<'_> {
5466
fn eq(&self, other: &(&str, u16, bool)) -> bool {
5567
self.host == other.0 && self.port == other.1 && self.tls == other.2
@@ -380,9 +392,13 @@ mod tests {
380392
let endpoint = EndpointRef::new("host", 2181, false);
381393
assert_eq!(endpoint.to_string(), "tcp://host:2181");
382394
assert_eq!(endpoint.to_value().to_string(), "tcp://host:2181");
395+
assert_eq!(format!("{:?}", endpoint), "tcp://host:2181");
396+
assert_eq!(format!("{:?}", endpoint.to_value()), "tcp://host:2181");
383397

384398
let endpoint = EndpointRef::new("host", 2182, true);
385399
assert_eq!(endpoint.to_string(), "tcp+tls://host:2182");
386400
assert_eq!(endpoint.to_value().to_string(), "tcp+tls://host:2182");
401+
assert_eq!(format!("{:?}", endpoint), "tcp+tls://host:2182");
402+
assert_eq!(format!("{:?}", endpoint.to_value()), "tcp+tls://host:2182");
387403
}
388404
}

0 commit comments

Comments
 (0)