pub enum LocalAddressType {
Localhost,
Unspecified,
}Variants§
Implementations§
source§impl LocalAddressType
impl LocalAddressType
sourcepub const fn to_ip_v4(&self) -> Ipv4Addr
pub const fn to_ip_v4(&self) -> Ipv4Addr
Examples found in repository?
src/utils.rs (line 10)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
pub fn find_available_port(search: bool, start_port: u16, local_address_type: LocalAddressType) -> Option<u16> {
if search {
find_available_port_in_range(start_port..MAX_PORT, local_address_type)
} else {
let local_address = local_address_type.to_ip_v4();
TcpListener::bind((local_address, start_port))
.is_ok()
.then_some(start_port)
}
}
/// finds an available port within a range
#[must_use]
pub fn find_available_port_in_range<R>(mut range: R, local_address_type: LocalAddressType) -> Option<u16>
where
R: ExactSizeIterator<Item = u16>,
{
let local_address = local_address_type.to_ip_v4();
range.find(|port| TcpListener::bind((local_address, *port)).is_ok())
}Trait Implementations§
source§impl Clone for LocalAddressType
impl Clone for LocalAddressType
source§fn clone(&self) -> LocalAddressType
fn clone(&self) -> LocalAddressType
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more