[][src]Struct tweep::ErrorList

pub struct ErrorList {
    pub errors: Vec<Error>,
}

A wrapper type for a list of Errors

Fields

errors: Vec<Error>

The list of Errors

Implementations

impl ErrorList[src]

pub fn new() -> Self[src]

Creates a new ErrorList

Examples

use tweep::ErrorList;
let errors = ErrorList::new();

pub fn push(&mut self, error: Error)[src]

Adds the given Error to the list

Examples

use tweep::{Error, ErrorList, ErrorKind, FullContext};
let mut errors = ErrorList::default();
let context = FullContext::from(None, "::".to_string());
errors.push(Error::new(ErrorKind::EmptyName, Some(context.clone())));

pub fn is_empty(&self) -> bool[src]

Returns true if the list is empty

Examples

use tweep::ErrorList;
let errors = ErrorList::new();
assert!(errors.is_empty());

pub fn merge<T, U>(
    left: &mut Result<T, ErrorList>,
    right: &mut Result<U, ErrorList>
) -> Result<(), ErrorList>
[src]

Given two Results with ErrorList as the Err type, returns:

  • Ok(()) if both inputs are Ok
  • The ErrorList contained by the Err input if one input is Err
  • The ErrorList of right appended to the ErrorList of left if both inputs are Err

Note that T and U do not need to have any relation to each other.

Examples

When given two Ok variant inputs, returns Ok(()):

use tweep::ErrorList;
let mut left:Result<u8, ErrorList> = Ok(5);
let mut right:Result<&str, ErrorList> = Ok("foo");
let merged = ErrorList::merge(&mut left, &mut right);
assert_eq!(merged, Ok(()));

When given one Ok and one Err, the output will have the same list of errors as the Err variant:

use tweep::{Error, ErrorList, ErrorKind, FullContext, Position};
let mut left:Result<u8, ErrorList> = Ok(5);
let right_context = FullContext::from(None, "::".to_string());
let mut right:Result<&str, ErrorList> = Err(ErrorList {
    errors: vec![ Error::new(ErrorKind::EmptyName, Some(right_context.clone())) ],
});
let merged = ErrorList::merge(&mut left, &mut right);
assert_eq!(merged.err().unwrap().errors, vec![ Error::new(ErrorKind::EmptyName, Some(right_context.clone())) ]);

When given two Err variants, the output will be have an ErrorList that contains the errors in right appended to the errors in left

use tweep::{Error, ErrorList, ErrorKind, FullContext, Position};
let left_context = FullContext::from(None, "::".to_string());
let mut left:Result<u8, ErrorList> = Err(ErrorList {
    errors: vec![ Error::new(ErrorKind::EmptyName, Some(left_context.clone())) ],
});
let right_context = FullContext::from(None, " :: Blah".to_string());
let mut right:Result<&str, ErrorList> = Err(ErrorList {
    errors: vec![ Error::new(ErrorKind::LeadingWhitespace, Some(right_context.clone())) ],
});
let merged = ErrorList::merge(&mut left, &mut right);
assert_eq!(merged.err().unwrap().errors, vec![ Error::new(ErrorKind::EmptyName, Some(left_context.clone())), Error::new(ErrorKind::LeadingWhitespace, Some(right_context.clone())) ]);

Trait Implementations

impl Debug for ErrorList[src]

impl Default for ErrorList[src]

impl Display for ErrorList[src]

impl Eq for ErrorList[src]

impl Error for ErrorList[src]

impl From<Error> for ErrorList[src]

impl PartialEq<ErrorList> for ErrorList[src]

impl StructuralEq for ErrorList[src]

impl StructuralPartialEq for ErrorList[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.