Struct PortPicker

Source
pub struct PortPicker { /* private fields */ }
Expand description

PortPicker is a simple library to pick a free port in the local machine.

It can be used to find a free port to start a server or any other use case.

#Examples:

use random_port::PortPicker;
let port = PortPicker::new().pick().unwrap();
println!("The free port is {}", port);

Implementations§

Source§

impl PortPicker

Source

pub fn new() -> Self

Source

pub fn port_range(self, range: RangeInclusive<u16>) -> Self

Specifies the range of ports to check. Must be in the range 1024..=65535. E.g. port_range(1024..=65535).

Source

pub fn execlude(self, exclude: HashSet<u16>) -> Self

Specifies the ports to exclude.

Source

pub fn execlude_add(self, port: u16) -> Self

Specifies a port to exclude.

Source

pub fn protocol(self, protocol: Protocol) -> Self

Specifies the protocol to check, Default is Protocol::All. Can be either Protocol::Tcp, Protocol::Udp or Protocol::All.

Source

pub fn host(self, host: String) -> Self

Specifies the host to check. Can be either an Ipv4 or Ipv6 address. If not specified, will checks availability on all local addresses defined in the system.

Source

pub fn random(self, random: bool) -> Self

Specifies whether to pick a random port from the range. If not specified, will pick the first available port from the range.

Source

pub fn pick(&self) -> Result<u16>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V