pub struct Errors(/* private fields */);Expand description
Every problem found while reading a configuration.
Constructed by crate::Reader::finish. It is never empty: a reader
with no problems returns Ok instead.
It renders one problem per line, so a process’s last words are the whole list rather than the first item of it.
§Examples
use env_reader::Reader;
let mut reader = Reader::from_pairs([("PORT", "two")]);
let _: String = reader.required_string("SERVICE_NAME");
let _: u16 = reader.integer_or("PORT", 8080);
let errors = reader.finish().unwrap_err();
assert_eq!(errors.len(), 2);
assert_eq!(
errors.to_string(),
"missing required configuration: SERVICE_NAME\n\
invalid configuration: PORT must be a whole number, got \"two\""
);Implementations§
Source§impl Errors
impl Errors
Sourcepub fn new(errors: Vec<Error>) -> Self
pub fn new(errors: Vec<Error>) -> Self
Wrap a non-empty list of problems.
§Panics
Panics if errors is empty. An empty error is not a thing this type
can represent, and a caller that has none should be returning Ok.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
How many problems there are.
§Examples
use env_reader::{Error, Errors};
let errors = Errors::new(vec![Error::missing("PORT")]);
assert_eq!(errors.len(), 1);
assert!(!errors.is_empty());Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Always false; see Errors::new.
Present because clippy asks for it beside Errors::len, and
because a caller writing if errors.is_empty() deserves an answer
rather than a compile error.
Sourcepub fn iter(&self) -> Iter<'_, Error> ⓘ
pub fn iter(&self) -> Iter<'_, Error> ⓘ
The problems, in the order they were found.
§Examples
use env_reader::{Error, Errors};
let errors = Errors::new(vec![Error::missing("A"), Error::missing("B")]);
let names: Vec<_> = errors.iter().filter_map(Error::name).collect();
assert_eq!(names, ["A", "B"]);Sourcepub fn into_inner(self) -> Vec<Error>
pub fn into_inner(self) -> Vec<Error>
The problems, consuming this.
Trait Implementations§
impl Eq for Errors
Source§impl Error for Errors
impl Error for Errors
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl<'a> IntoIterator for &'a Errors
impl<'a> IntoIterator for &'a Errors
Source§impl IntoIterator for Errors
impl IntoIterator for Errors
impl StructuralPartialEq for Errors
Auto Trait Implementations§
impl Freeze for Errors
impl RefUnwindSafe for Errors
impl Send for Errors
impl Sync for Errors
impl Unpin for Errors
impl UnsafeUnpin for Errors
impl UnwindSafe for Errors
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more