expression
Reject invalid endpoint text
Validate a numeric endpoint before use. A port must fit u16; parsing a SocketAddr is not hostname resolution. Return the error instead of guessing a corrected destination. Expected stdout (not executed): true false false Common mistake: Silently replacing an invalid destination with a default network endpoint.
Formal Syntax & Structure
rust syntaxrust
text.parse::<SocketAddr>() -> Result<SocketAddr, AddrParseError>Working Example
Example Snippetrust
fn main() { use std::net::SocketAddr; for text in ["127.0.0.1:8080", "127.0.0.1:70000", "300.0.0.1:80"] { println!("{}", text.parse::<SocketAddr>().is_ok()); }}