2024年12月24日

上面这段代码,?的作用是: 如果返回Result::OK(T),则f类型为T; 如果返回Result::Err(error),则函数返回Result::Err(error) 是这个意思呗?

摘要: use std::fs::File; use std::io; use std::io::Read; fn read_username_from_file() -> Result<String, io::Error> { let mut f = File::open("hello.txt")?; l 阅读全文

posted @ 2024-12-24 16:00 及途又八 阅读(34) 评论(0) 推荐(0)

看下面这个Rust程序,我想知道 other_error => panic!("Problem opening the file: {:?}", other_error) 这一行代码,为什么是other_error => panic...而不是_ => panic... ?

摘要: 看下面这个Rust程序,我想知道 other_error => panic!("Problem opening the file: {:?}", other_error) 这一行代码,为什么是other_error => panic...而不是_ => panic... ? use std::fs: 阅读全文

posted @ 2024-12-24 15:40 及途又八 阅读(15) 评论(0) 推荐(0)

导航