Guest User

Untitled

a guest
May 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 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. fn main() -> Result<()> {
  17. // ...
  18. Ok(())
  19. }
  20.  
  21. #[test]
  22. fn test() {
  23. use super::Foo;
  24.  
  25. let result = Foo::example_fn("foo.txt");
  26.  
  27. assert!(/* verify Err(std::io::Error(Simple(std::io::ErrorKind::NotFound))) was received */ );
  28. }
Add Comment
Please, Sign In to add comment