use std::io::ErrorKind; use std::net::TcpStream; fn main() { let address = "localhost:7000"; loop { match TcpStream::connect(address.clone()) { Err(err) => { match err.kind() { ErrorKind::ConnectionRefused => { continue; }, kind => panic!("Error occurred: {:?}", kind), }; }, Ok(_stream) => { }, } } }
Consider the rust code snippet above. I'm not interested in the Ok branch, but rather the ErrorKind::ConnectionRefused branch associated with loop : it is very cheap, processor, consumes less than 1% of the processor. This is great, this is what I want.
But I donβt understand why it is cheap: comparable code in C is likely to consume 100% mostly NOP ing (not exactly, but close enough). Can someone help me understand why it is so cheap?
source share