Port

Struct Port 

Source
pub struct Port(/* private fields */);
Expand description

NewType wrapper for ports to provide type safety Uses NonZeroU16 internally to guarantee valid port numbers (1-65535)

Implementations§

Source§

impl Port

Source

pub const fn new(port: u16) -> Option<Self>

Create a new port, validating it’s not zero

Source

pub const fn system_port(port: u16) -> Option<Self>

Create a port from a system port number (0-1023)

System Ports (per RFC 6335) are reserved for system services and require elevated privileges.

Source

pub const fn user_port(port: u16) -> Option<Self>

Create a port from a user port number range (1024-49151)

User Ports (per RFC 6335) are assigned by IANA for user applications.

Source

pub const fn dynamic_port(port: u16) -> Option<Self>

Create a port from a dynamic port number range (49152-65535)

Dynamic Ports (per RFC 6335) are used for temporary or private connections.

Source

pub const fn new_unchecked(port: u16) -> Self

Create a new port without validation (for known valid values) Only use this when you know the port is valid (not zero)

This method is safe because it panics at compile-time if called with an invalid port number (like 0), preventing runtime errors. It’s optimized for known valid port constants.

Source

pub const fn http() -> Self

Common HTTP port (80)

Source

pub const fn https() -> Self

Common HTTPS port (443)

Source

pub const fn ssh() -> Self

Common SSH port (22)

Source

pub const fn postgres() -> Self

Common PostgreSQL port (5432)

Source

pub const fn mysql() -> Self

Common MySQL port (3306)

Source

pub const fn redis() -> Self

Common Redis port (6379)

Source

pub const fn get(&self) -> u16

Get the inner port value

Source

pub const fn is_system_port(&self) -> bool

Check if this port is a System Port (0-1023)

System Ports (per RFC 6335) are reserved for system services and require elevated privileges.

§Examples
use waitup::Port;

let http = Port::http();
assert!(http.is_system_port());

let app_port = Port::new(8080).unwrap();
assert!(!app_port.is_system_port());
Source

pub const fn is_user_port(&self) -> bool

Check if this port is a User Port (1024-49151)

User Ports (per RFC 6335) are assigned by IANA for user applications.

§Examples
use waitup::Port;

let app_port = Port::new(8080).unwrap();
assert!(app_port.is_user_port());

let http = Port::http();
assert!(!http.is_user_port());
Source

pub const fn is_dynamic_port(&self) -> bool

Check if this port is a Dynamic Port (49152-65535)

Dynamic Ports (per RFC 6335) are used for temporary or private connections.

§Examples
use waitup::Port;

let ephemeral = Port::new(50000).unwrap();
assert!(ephemeral.is_dynamic_port());

let http = Port::http();
assert!(!http.is_dynamic_port());
Source

pub const fn category(&self) -> PortCategory

Get the RFC 6335 category for this port

Returns the port category (System, User, or Dynamic) as defined by RFC 6335. This method enables exhaustive pattern matching on port categories.

§Examples
use waitup::{Port, PortCategory};

let http = Port::http();
assert_eq!(http.category(), PortCategory::System);

let app_port = Port::new(8080).unwrap();
assert_eq!(app_port.category(), PortCategory::User);

let ephemeral = Port::new(50000).unwrap();
assert_eq!(ephemeral.category(), PortCategory::Dynamic);

// Pattern matching example
match http.category() {
    PortCategory::System => println!("Requires elevated privileges"),
    PortCategory::User => println!("Standard application port"),
    PortCategory::Dynamic => println!("Temporary/ephemeral port"),
    _ => {} // Required due to #[non_exhaustive]
}

Trait Implementations§

Source§

impl Clone for Port

Source§

fn clone(&self) -> Port

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Port

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Port

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Port> for NonZeroU16

Source§

fn from(port: Port) -> Self

Converts to this type from the input type.
Source§

impl From<Port> for u16

Source§

fn from(port: Port) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Port

Parse port from string representations

Source§

type Err = WaitForError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Port

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Port

Source§

fn cmp(&self, other: &Port) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Port

Source§

fn eq(&self, other: &Port) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Port

Source§

fn partial_cmp(&self, other: &Port) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<NonZero<u16>> for Port

Source§

type Error = WaitForError

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

fn try_from(port: NonZeroU16) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<i32> for Port

Source§

type Error = WaitForError

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

fn try_from(port: i32) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<u16> for Port

Source§

type Error = WaitForError

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

fn try_from(port: u16) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<u32> for Port

Source§

type Error = WaitForError

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

fn try_from(port: u32) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<usize> for Port

Source§

type Error = WaitForError

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

fn try_from(port: usize) -> Result<Self>

Performs the conversion.
Source§

impl Copy for Port

Source§

impl Eq for Port

Source§

impl StructuralPartialEq for Port

Auto Trait Implementations§

§

impl Freeze for Port

§

impl RefUnwindSafe for Port

§

impl Send for Port

§

impl Sync for Port

§

impl Unpin for Port

§

impl UnwindSafe for Port

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,