Guest User

Untitled

a guest
Oct 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #![feature(nll)]
  2.  
  3. use std::result;
  4.  
  5. #[derive(Debug)]
  6. pub struct Error<'a>(&'a u8);
  7.  
  8. pub type Result<'a, T> = result::Result<T, Error<'a>>;
  9. pub struct Context;
  10.  
  11. impl Context {
  12. pub fn open<'a>(&'a mut self) -> Result<'a, ()> {
  13. Err(Error(&0))
  14. }
  15.  
  16. pub fn close<'a>(&'a self) -> Result<'a, ()> {
  17. Err(Error(&0))
  18. }
  19. }
  20.  
  21. fn bar(ctx : &mut Context) -> Result<()> {
  22. match ctx.open() { Err(e) => return Err(e), Ok(x) => x };
  23. let _ = ctx.close();
  24. Ok(())
  25. }
  26.  
  27. fn main() {
  28. let mut ctx = Context;
  29. let res = bar(&mut ctx).unwrap_err();
  30. println!("{:?}",res);
  31. }
Add Comment
Please, Sign In to add comment