Guest User

Untitled

a guest
May 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. extern crate failure;
  2. use error::Error;
  3. use std::fs::File;
  4.  
  5. type Result<T> = std::result::Result<T, Error>;
  6.  
  7. mod error {
  8. use std::io::Error as IoError;
  9. use super::Result;
  10.  
  11. #[derive(Debug, PartialEq/*<- ruh roh!*/)]
  12. pub enum Error {
  13. MyVariant(IoError),
  14. }
  15.  
  16. impl Display...
  17.  
  18. impl From<IoError> for Error...
  19.  
  20. struct Foo {}
  21.  
  22. impl Foo {
  23. fn example_fn(name: &str) -> Result<File> {
  24. match File::open(name)?
  25. }
  26.  
  27. fn main() -> Result<()> {
  28. // ...
  29. Ok(())
  30. }
  31.  
  32. #[test]
  33. fn test() {
  34. use super::{Error, Foo};
  35.  
  36. let result = Foo::example_fn("foo.txt");
  37.  
  38. // Verify Err(Error::MyVariant(std::io::Error(Simple(std::io::ErrorKind::NotFound)))) was received
  39. assert!(result == ???);
  40. }
Add Comment
Please, Sign In to add comment