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
impl Port
Sourcepub const fn system_port(port: u16) -> Option<Self>
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.
Sourcepub const fn user_port(port: u16) -> Option<Self>
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.
Sourcepub const fn dynamic_port(port: u16) -> Option<Self>
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.
Sourcepub const fn new_unchecked(port: u16) -> Self
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.
Sourcepub const fn is_system_port(&self) -> bool
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());Sourcepub const fn is_user_port(&self) -> bool
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());Sourcepub const fn is_dynamic_port(&self) -> bool
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());Sourcepub const fn category(&self) -> PortCategory
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 From<Port> for NonZeroU16
impl From<Port> for NonZeroU16
Source§impl Ord for Port
impl Ord for Port
Source§impl PartialOrd for Port
impl PartialOrd for Port
Source§impl TryFrom<NonZero<u16>> for Port
impl TryFrom<NonZero<u16>> for Port
Source§type Error = WaitForError
type Error = WaitForError
Source§fn try_from(port: NonZeroU16) -> Result<Self>
fn try_from(port: NonZeroU16) -> Result<Self>
impl Copy for Port
impl Eq for Port
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.