pub type Result<T> = Result<T, Error>;Expand description
The type returned by parser methods.
§Examples
use estring::{EString, ParseFragment, Reason};
#[derive(Debug, PartialEq)]
struct Point {
x: i32,
y: i32,
}
impl ParseFragment for Point {
fn parse_frag(es: EString) -> estring::Result<Self> {
let orig = es.clone();
let (x, y) = es
.trim_matches(|p| p == '(' || p == ')')
.split_once(',')
.ok_or(estring::Error(orig, Reason::Split))?;
let (x, y) = (EString::from(x), EString::from(y));
let x = x.clone().parse::<i32>()
.map_err(|_| estring::Error(x, Reason::Parse))?;
let y = y.clone().parse::<i32>()
.map_err(|_| estring::Error(y, Reason::Parse))?;
Ok(Point { x, y })
}
}
let fragment = EString::from("(1,2)");
let res = Point::parse_frag(fragment).unwrap();
assert_eq!(res, Point { x: 1, y: 2 })Aliased Type§
pub enum Result<T> {
Ok(T),
Err(Error),
}