Guest User

Untitled

a guest
Jul 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #![feature(try_trait)]
  2.  
  3. #[derive(Debug)]
  4. struct Error(String);
  5. type MyRes<T> = Result<T, Error>;
  6.  
  7. impl From<std::option::NoneError> for Error {
  8. fn from(_: std::option::NoneError) -> Error {
  9. Error(format!("Null pointer exception"))
  10. }
  11. }
  12.  
  13. impl From<std::num::ParseIntError> for Error {
  14. fn from(e: std::num::ParseIntError) -> Error {
  15. Error(format!("Parse error {}", e))
  16. }
  17. }
  18.  
  19. fn parse(line: &str) -> MyRes<(u64, u64)> {
  20. let mut iter = line.split('x');
  21. let first: u64 = iter.next()?.parse()?;
  22. let second: u64 = iter.next()?.parse()?;
  23. Ok((first, second))
  24. }
  25.  
  26.  
  27. pub fn main() {
  28. let (a,b) = parse("65x78").unwrap();
  29. println!("{} and {}", a, b);
  30. parse("65").unwrap();
  31. }
Add Comment
Please, Sign In to add comment