proxy: Added DisplayableRealAddr
As displaying real_addr happens many times in the code, after we change
it to an option we should handle None DRY. For that purpose, we created
DisplayableRealAddr, which is a wrapper that knows how to display it.
We create it in-place, inside a print call.
@@ -7,6 +7,7 @@ use crate::RequestOpcode;
use bytes::Bytes;
use scylla_cql::frame::types::read_string_multimap;
use std::collections::HashMap;
+use std::fmt::Display;
use std::future::Future;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
@@ -152,6 +153,18 @@ impl NodeBuilder {
}
}
+#[derive(Clone, Copy)]
+struct DisplayableRealAddrOption(Option<SocketAddr>);
+impl Display for DisplayableRealAddrOption {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ if let Some(addr) = self.0 {
+ write!(f, "{}", addr)
+ } else {
+ unimplemented!()
+ }
+ }
+}
+
struct InternalNode {
real_addr: SocketAddr,
proxy_addr: SocketAddr,
