在 tokio::net::TcpStream 的情况下,我坚持正确处理恐慌
use tokio::*;
use tokio::{net::{ TcpStream }, io::AsyncWriteExt};
#[tokio::main]
async fn main() {
let mut stream = TcpStream::connect("10.20.30.40:6142").await.unwrap();
println!("created stream");
let result = stream.write(b"hello world\n").await;
println!("wrote to stream; success={:?}", result.is_ok());
}
或在操场上
大师可以教我如何捕捉这些错误,例如
线程'main'在'调用
Result::unwrap()
一个Err
值时惊慌失措:Os {代码:101,种类:NetworkUnreachable,消息:“网络无法访问”}',src/main.rs:6:67