Browse Source

refactor

ipv6
Denis Drakhnia 3 months ago
parent
commit
0d1b06b207
  1. 10
      master/src/master_server.rs

10
master/src/master_server.rs

@ -9,6 +9,7 @@ use std::{
io, io,
net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs, UdpSocket}, net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs, UdpSocket},
ops::Deref, ops::Deref,
str::FromStr,
sync::atomic::{AtomicBool, Ordering}, sync::atomic::{AtomicBool, Ordering},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
@ -35,7 +36,7 @@ use crate::{
}; };
pub trait AddrExt: Sized + Eq + Hash + Display + Copy + ToSocketAddrs + ServerAddress { pub trait AddrExt: Sized + Eq + Hash + Display + Copy + ToSocketAddrs + ServerAddress {
type Ip; type Ip: Eq + Hash + Display + Copy + FromStr;
fn extract(addr: SocketAddr) -> Result<Self, SocketAddr>; fn extract(addr: SocketAddr) -> Result<Self, SocketAddr>;
fn ip(&self) -> &Self::Ip; fn ip(&self) -> &Self::Ip;
@ -261,11 +262,7 @@ impl Master {
} }
} }
impl<Addr> MasterServer<Addr> impl<Addr: AddrExt> MasterServer<Addr> {
where
Addr: AddrExt,
Addr::Ip: Eq + Hash + Display + Copy + std::str::FromStr,
{
pub fn new(cfg: Config, addr: Addr) -> Result<Self, Error> { pub fn new(cfg: Config, addr: Addr) -> Result<Self, Error> {
info!("Listen address: {}", addr); info!("Listen address: {}", addr);
@ -694,7 +691,6 @@ where
fn helper<Addr, F>(args: &[&str], mut op: F) fn helper<Addr, F>(args: &[&str], mut op: F)
where where
Addr: AddrExt, Addr: AddrExt,
Addr::Ip: std::str::FromStr,
F: FnMut(&str, Addr::Ip), F: FnMut(&str, Addr::Ip),
{ {
let iter = args.iter().map(|i| (i, i.parse::<Addr::Ip>())); let iter = args.iter().map(|i| (i, i.parse::<Addr::Ip>()));

Loading…
Cancel
Save