SHARE
TWEET

Untitled

a guest Oct 19th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::num::ParseIntError;
  2.  
  3. pub enum ParseError {
  4.     Invalid,
  5.     ParseIntError(ParseIntError),
  6. }
  7.  
  8. impl From<ParseIntError> for ParseError {
  9.     fn from(err: ParseIntError) -> Self {
  10.         ParseError::ParseIntError(err)
  11.     }
  12. }
  13.  
  14. fn parse(s: &str) -> Result<(u32, u32), ParseError> {
  15.     let mut parts = s.split(':');
  16.    
  17.     let x = parts.next()
  18.         .ok_or(ParseError::Invalid)?
  19.         .parse::<u32>()?;
  20.        
  21.     let y = parts.next()
  22.         .ok_or(ParseError::Invalid)?
  23.         .parse::<u32>()?;
  24.        
  25.     Ok((x, y))
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top