Result & Panic

这次讲得详细,从错误的来历及简写过程,

都写明白了,

先浅,再深,先深,再浅,

反复之,

学习王道~

use std::fs::File;
//use std::io::ErrorKind;

fn main() {
    //panic!("crash and burn");
    //let v = vec![1, 2, 3];
    //v[99];
    /*
    let f = File::open("hello.txt");

    let f = match f {
    Ok(file) => file,
    Err(error) => match error.kind() {
        ErrorKind::NotFound => match File::create("hello.txt") {
        Ok(fc) => fc,
        Err(e) => panic!("Try create new file, but error : {:#?}", e),
        },
        other_error => panic!("There was a problem opening the file: {:#?}", other_error),
    },
    };

    let f = File::open("hello.txt").map_err(|error| {
    if error.kind() == ErrorKind::NotFound {
        File::create("hello.txt").unwrap_or_else(|error| {
        panic!("Try create new file, but error : {:#?}", error);
        })
    } else {
        panic!("There was a problem opening the file: {:#?}", error);
    }
    });
    */

    //let f = File::open("hello.txt").unwrap();
    let f = File::open("hello.txt").expect("Failed to open hello.txt");
    println!("f value is {:#?}", f);
}

最新文章

  1. Hibernate 更新部分字段的实现
  2. SVN批处理
  3. linux配置ftp
  4. RCP:eclipse的DEBUG机制
  5. 【Java基础】RTTI与反射之Java
  6. Android 开源项目
  7. 关于常用的git命令列表
  8. centos下的lnmp环境搭建
  9. int, NSInteger, NSUInteger, NSNumber的区别
  10. KendoUI 用下来的小总结
  11. Tomcat简单优化
  12. Baidu 人脸识别FireFly 与PC连接调试
  13. AI-restful接口写法
  14. [CB]2018全球半导体营收4700亿美元 三星继续碾压英特尔
  15. C# ffmpeg工具将视频转为SWF格式
  16. mysql 压缩备份 压缩还原 命令
  17. 部署ArcGIS JS API 离线包(Tomcat与IIS)
  18. Intellij Idea常用配置设置
  19. 自己定义带三角形箭头的TextView
  20. nodejs知识点

热门文章

  1. 如何将list集合转成String对象
  2. git报错_you are not allowed to push code to protected branches on this project
  3. luoguP2178 [NOI2015]品酒大会(后缀自动机)
  4. SqlServer断开所有连接
  5. 优雅的阅读CSDN博客
  6. Python Dataframe 分组排序和 Modin
  7. [NewLife.XCode]实体工厂(拦截处理实体操作)
  8. python实现语音信号处理常用度量方法
  9. 在macOS苹果电脑上安装Azure DevOps Server(TFS)代理
  10. 微服务 SpringCloud + docker