pub struct PatternError { /* private fields */ }Expand description
An error returned when a pattern is not syntactically valid.
offset is a zero-based byte offset into the pattern, so
a caller can point at the construct that failed. Display reads
<message> at byte <offset>; the message is diagnostic text, while the
offset is the stable part.
use ferralk_glob::{Pattern, PatternOptions};
let source = "src/[a-z/*.rs";
let error = Pattern::compile(source, PatternOptions::walker()).unwrap_err();
assert_eq!(error.offset(), 4); // the `[` that is never closed
// A byte offset is a column only for ASCII; count the characters before it
// to place a marker under any pattern.
let column = source[..error.offset()].chars().count();
let report = format!("{error}\n{source}\n{:>width$}", "^", width = column + 1);
assert!(report.ends_with("src/[a-z/*.rs\n ^"));Implementations§
Source§impl PatternError
impl PatternError
Sourcepub const fn new(offset: usize, message: &'static str) -> Self
pub const fn new(offset: usize, message: &'static str) -> Self
Builds an error for a pattern a layer above the matcher rejected.
Compilation produces these on its own; this exists for callers that
impose rules the pattern language cannot express, such as a walker
deciding that an absolute pattern cannot be rewritten for its root. Such
a caller already returns PatternError, and a second error type in the
same position would say nothing extra.
offset is a byte offset into the pattern the caller was given, and
message describes the construct rather than the caller’s own state, so
that Display reads the same as a compilation error.
Sourcepub const fn message(&self) -> &'static str
pub const fn message(&self) -> &'static str
Description of the invalid construct.
This text is intended for diagnostics and is not a stable interface;
use Self::offset for programmatic handling.
Trait Implementations§
Source§impl Clone for PatternError
impl Clone for PatternError
Source§impl Debug for PatternError
impl Debug for PatternError
Source§impl Display for PatternError
impl Display for PatternError
impl Eq for PatternError
Source§impl Error for PatternError
impl Error for PatternError
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()