Error handling 有没有办法从std::io::error获取操作系统错误代码?

Error handling 有没有办法从std::io::error获取操作系统错误代码?,error-handling,rust,Error Handling,Rust,当我运行以下命令时: 使用std::fs::File; fn main(){ 让filename=“not_exists.txt”; 让reader=File::open(文件名); 匹配阅读器{ 确定()=>println!(“*文件{}已成功打开。”,文件名), 错误(e)=>{ println!({:?},&e); } } } 输出为: Os{code:2,种类:NotFound,消息:“没有这样的文件或目录”} 是否可以将该代码作为整数获取?使用: 匹配读取器{ 确定()=>prin

当我运行以下命令时:

使用std::fs::File;
fn main(){
让filename=“not_exists.txt”;
让reader=File::open(文件名);
匹配阅读器{
确定()=>println!(“*文件{}已成功打开。”,文件名),
错误(e)=>{
println!({:?},&e);
}
}
}
输出为:

Os{code:2,种类:NotFound,消息:“没有这样的文件或目录”}
是否可以将该代码作为整数获取?

使用:

匹配读取器{
确定()=>println!(“*文件{}已成功打开。”,文件名),
Err(e)=>println!(“{:?}”,e.raw_os_error()),
}
输出:

Some(2)
另见:

使用:

匹配读取器{
确定()=>println!(“*文件{}已成功打开。”,文件名),
Err(e)=>println!(“{:?}”,e.raw_os_error()),
}
输出:

Some(2)
另见:

是,使用
std::io::Error
上的方法。例如:

使用std::fs::File;
fn main(){
让filename=“not_exists.txt”;
让reader=File::open(文件名);
匹配阅读器{
确定()=>println!(“*文件{}已成功打开。”,文件名),
错误(e)=>{
println!(“{:?}{:?}”,e,e.raw_os_error());
}
}
}

是,使用
std::io::Error
上的方法。例如:

使用std::fs::File;
fn main(){
让filename=“not_exists.txt”;
让reader=File::open(文件名);
匹配阅读器{
确定()=>println!(“*文件{}已成功打开。”,文件名),
错误(e)=>{
println!(“{:?}{:?}”,e,e.raw_os_error());
}
}
}

谢谢,这正是我要找的。谢谢,这正是我要找的。