mirror of
https://github.com/zaphar/abortable_parser.git
synced 2025-07-21 20:29:49 -04:00
FEATURE: Require Debug be implemented for err
in the Error
struct.
This commit is contained in:
parent
bb3502d6fd
commit
fe1b0fd154
12
src/lib.rs
12
src/lib.rs
@ -1,5 +1,5 @@
|
|||||||
//! A parser combinator library with a focus on fully abortable parsing and error handling.
|
//! A parser combinator library with a focus on fully abortable parsing and error handling.
|
||||||
use std::fmt::Display;
|
use std::fmt::{Debug, Display};
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
|
||||||
/// A trait for types that can have an offset as a count of processed items.
|
/// A trait for types that can have an offset as a count of processed items.
|
||||||
@ -20,13 +20,13 @@ pub trait InputIter: Iterator + Clone + Offsetable {}
|
|||||||
/// Stores a wrapped err that must implement Display as well as an offset and
|
/// Stores a wrapped err that must implement Display as well as an offset and
|
||||||
/// an optional cause.
|
/// an optional cause.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Error<E: Display> {
|
pub struct Error<E: Display + Debug> {
|
||||||
err: E,
|
err: E,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
cause: Option<Box<Error<E>>>,
|
cause: Option<Box<Error<E>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Display> Error<E> {
|
impl<E: Display + Debug> Error<E> {
|
||||||
/// Constructs a new Error with an offset and no cause.
|
/// Constructs a new Error with an offset and no cause.
|
||||||
pub fn new<S: Offsetable>(err: E, offset: &S) -> Self {
|
pub fn new<S: Offsetable>(err: E, offset: &S) -> Self {
|
||||||
Error {
|
Error {
|
||||||
@ -64,7 +64,7 @@ impl<E: Display> Error<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Display> Display for Error<E> {
|
impl<E: Display + Debug> Display for Error<E> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
|
||||||
try!(write!(f, "{}", self.err));
|
try!(write!(f, "{}", self.err));
|
||||||
match self.cause {
|
match self.cause {
|
||||||
@ -76,7 +76,7 @@ impl<E: Display> Display for Error<E> {
|
|||||||
|
|
||||||
/// The result of a parsing attempt.
|
/// The result of a parsing attempt.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Result<I: InputIter, O, E: Display> {
|
pub enum Result<I: InputIter, O, E: Display + Debug> {
|
||||||
/// Complete represents a successful match.
|
/// Complete represents a successful match.
|
||||||
Complete(I, O),
|
Complete(I, O),
|
||||||
/// Incomplete indicates input ended before a match could be completed.
|
/// Incomplete indicates input ended before a match could be completed.
|
||||||
@ -88,7 +88,7 @@ pub enum Result<I: InputIter, O, E: Display> {
|
|||||||
Abort(Error<E>),
|
Abort(Error<E>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: InputIter, O, E: Display> Result<I, O, E> {
|
impl<I: InputIter, O, E: Display + Debug> Result<I, O, E> {
|
||||||
/// Returns true if the Result is Complete.
|
/// Returns true if the Result is Complete.
|
||||||
pub fn is_complete(&self) -> bool {
|
pub fn is_complete(&self) -> bool {
|
||||||
if let &Result::Complete(_, _) = self {
|
if let &Result::Complete(_, _) = self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user