#[non_exhaustive]pub struct InputError {
pub name: String,
pub problems: Vec<Problem>,
/* private fields */
}json or toml or yaml only.Expand description
Why an input was refused: every problem found, each placed on a line when the text allows it.
Display prints one problem per line as name:line:column: field: message,
leaving out what is not known.
A file that could not be read keeps its io::ErrorKind, which
Self::io_failure returns. So a caller can treat a missing file apart
from a refused one. A field can join this type in a minor release.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringThe input’s name, usually its path.
problems: Vec<Problem>What is wrong, in the order found.
Implementations§
Source§impl InputError
impl InputError
Sourcepub fn try_new(
name: impl Into<String>,
problems: impl IntoIterator<Item = Problem>,
) -> Option<Self>
pub fn try_new( name: impl Into<String>, problems: impl IntoIterator<Item = Problem>, ) -> Option<Self>
The problems a CLI found in the input name, in the order given, so
it reports its own refusals as ctl-core reports garde’s. Each
Problem is placed with Input::place or Input::problem_at,
or carries no line.
Returns None when problems is empty, since an error with no problem
would print nothing. So a CLI hands it every check’s findings and
refuses the input only when one turned up.
§Examples
use ctl_input::{InputError, Problem};
let refused = InputError::try_new(
"compose.yaml",
[Problem {
line: Some(4),
column: Some(5),
field: "services.dev.privileged".to_owned(),
message: "this host runs no privileged service".to_owned(),
}],
);
assert_eq!(
refused.map(|error| error.to_string()).as_deref(),
Some("compose.yaml:4:5: services.dev.privileged: this host runs no privileged service")
);
assert_eq!(InputError::try_new("compose.yaml", []), None);Sourcepub fn whole(name: impl Into<String>, message: impl Into<String>) -> Self
pub fn whole(name: impl Into<String>, message: impl Into<String>) -> Self
A refusal of the whole input name, on no line and no field, such as
a value that only makes sense once the file is read whole.
§Examples
use ctl_input::InputError;
let error = InputError::whole("compose.yaml", "the file names no service");
assert_eq!(error.to_string(), "compose.yaml: the file names no service");Sourcepub const fn io_failure(&self) -> Option<ErrorKind>
pub const fn io_failure(&self) -> Option<ErrorKind>
The I/O failure when the file could not be read, such as
io::ErrorKind::NotFound. None when the text was read and refused.
Trait Implementations§
Source§impl Clone for InputError
impl Clone for InputError
Source§impl Debug for InputError
impl Debug for InputError
Source§impl Display for InputError
One problem per line: name:line:column: field: message, leaving out
what is not known.
impl Display for InputError
One problem per line: name:line:column: field: message, leaving out
what is not known.
impl Eq for InputError
Source§impl Error for InputError
impl Error for InputError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for InputError
impl PartialEq for InputError
impl StructuralPartialEq for InputError
Auto Trait Implementations§
impl Forget for InputError
impl Freeze for InputError
impl Move for InputError
impl RefUnwindSafe for InputError
impl Send for InputError
impl Sync for InputError
impl Unpin for InputError
impl UnsafeUnpin for InputError
impl UnwindSafe for InputError
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, O> Matches<O> for Twhere
T: PartialEq<O>,
impl<T, O> Matches<O> for Twhere
T: PartialEq<O>,
fn validate_matches(&self, other: &O) -> bool
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more