Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(try_trait)]
- #[derive(Debug)]
- struct Error(String);
- type MyRes<T> = Result<T, Error>;
- impl From<std::option::NoneError> for Error {
- fn from(_: std::option::NoneError) -> Error {
- Error(format!("Null pointer exception"))
- }
- }
- impl From<std::num::ParseIntError> for Error {
- fn from(e: std::num::ParseIntError) -> Error {
- Error(format!("Parse error {}", e))
- }
- }
- fn parse(line: &str) -> MyRes<(u64, u64)> {
- let mut iter = line.split('x');
- let first: u64 = iter.next()?.parse()?;
- let second: u64 = iter.next()?.parse()?;
- Ok((first, second))
- }
- pub fn main() {
- let (a,b) = parse("65x78").unwrap();
- println!("{} and {}", a, b);
- parse("65").unwrap();
- }
Add Comment
Please, Sign In to add comment