is_valid_port

Function is_valid_port 

Source
pub fn is_valid_port(s: &str) -> bool
Expand description

Validates a port number string.

Checks if the string represents a valid TCP/UDP port number (1-65535). Port 0 is not considered valid.

§Arguments

  • s - The string to validate

§Returns

true if the string is a valid port number, false otherwise.

§Example

use stem_rs::util::is_valid_port;

assert!(is_valid_port("80"));
assert!(is_valid_port("443"));
assert!(is_valid_port("9051")); // Tor control port
assert!(is_valid_port("65535"));

assert!(!is_valid_port("0")); // Port 0 not valid
assert!(!is_valid_port("65536")); // Too large
assert!(!is_valid_port("abc")); // Non-numeric