Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fs::File;
- type Result<T> = std::result::Result<T, Box<std::error::Error>>;
- struct Foo {}
- impl Foo {
- fn example_fn(name: &str) -> Result<File> {
- match File::open(name) {
- Ok(v) => Ok(v),
- Err(e) => Err(Box::new(e)),
- }
- }
- }
- #[test]
- fn test() {
- let result = Foo::example_fn("foo.txt");
- let err = result.unwrap_err().downcast::<std::io::Error>().unwrap();
- assert_eq!(err.kind(), std::io::ErrorKind::NotFound);
- }
Add Comment
Please, Sign In to add comment