Guest User

Untitled

a guest
May 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. use std::fs::File;
  2.  
  3. type Result<T> = std::result::Result<T, Box<std::error::Error>>;
  4.  
  5. struct Foo {}
  6.  
  7. impl Foo {
  8. fn example_fn(name: &str) -> Result<File> {
  9. match File::open(name) {
  10. Ok(v) => Ok(v),
  11. Err(e) => Err(Box::new(e)),
  12. }
  13. }
  14. }
  15.  
  16.  
  17. #[test]
  18. fn test() {
  19. let result = Foo::example_fn("foo.txt");
  20. let err = result.unwrap_err().downcast::<std::io::Error>().unwrap();
  21. assert_eq!(err.kind(), std::io::ErrorKind::NotFound);
  22. }
Add Comment
Please, Sign In to add comment