[−][src]Struct tweep::ErrorList
A wrapper type for a list of Error
s
Fields
errors: Vec<Error>
The list of Error
s
Implementations
impl ErrorList
[src]
pub fn new() -> Self
[src]
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]
left: &mut Result<T, ErrorList>,
right: &mut Result<U, ErrorList>
) -> Result<(), ErrorList>
Given two Result
s with ErrorList
as the Err
type, returns:
Ok(())
if both inputs areOk
- The
ErrorList
contained by theErr
input if one input isErr
- The
ErrorList
ofright
appended to theErrorList
ofleft
if both inputs areErr
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]
fn source(&self) -> Option<&(dyn Error + 'static)>
[src]
fn backtrace(&self) -> Option<&Backtrace>
[src]
fn description(&self) -> &str
1.0.0[src]
fn cause(&self) -> Option<&dyn Error>
1.0.0[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
impl RefUnwindSafe for ErrorList
impl Send for ErrorList
impl Sync for ErrorList
impl Unpin for ErrorList
impl UnwindSafe for ErrorList
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,