pub struct CslParseError {
kind: CslParseErrorKind,
offset: usize,
}Expand description
A recoverable CSL parse error: a CslParseErrorKind plus the byte offset
into the original input where the problem was detected.
The offset is a byte index (the same convention mos-core SourceSpans
use). Use line_col for a 1-based line/column pair, or
to_diagnostic to bridge into the compiler
diagnostics pipeline.
§Examples
use mos_csl::{CslParseErrorKind, parse_style};
let err = parse_style("<not-a-style/>").unwrap_err();
assert!(matches!(err.kind(), CslParseErrorKind::UnexpectedRoot(_)));Fields§
§kind: CslParseErrorKind§offset: usizeImplementations§
Source§impl CslParseError
impl CslParseError
pub(crate) const fn new(kind: CslParseErrorKind, offset: usize) -> Self
Sourcepub const fn kind(&self) -> &CslParseErrorKind
pub const fn kind(&self) -> &CslParseErrorKind
The kind of parse failure.
Sourcepub const fn offset(&self) -> usize
pub const fn offset(&self) -> usize
The byte offset into the parsed input where the error was detected.
Sourcepub fn line_col(&self, src: &str) -> (usize, usize)
pub fn line_col(&self, src: &str) -> (usize, usize)
The 1-based (line, column) of this error within src.
src must be the input passed to parse_style;
columns count Unicode scalar values.
Sourcepub fn to_diagnostic(&self, file: impl Into<PathBuf>) -> Diagnostic
pub fn to_diagnostic(&self, file: impl Into<PathBuf>) -> Diagnostic
Convert this error into a mos-core [Diagnostic] anchored in file,
carrying the MOS0044 code and a zero-width span at
offset.
Trait Implementations§
Source§impl Clone for CslParseError
impl Clone for CslParseError
Source§fn clone(&self) -> CslParseError
fn clone(&self) -> CslParseError
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CslParseError
impl Debug for CslParseError
Source§impl Display for CslParseError
impl Display for CslParseError
Source§impl Error for CslParseError
impl Error for CslParseError
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 From<CslParseError> for CoreError
impl From<CslParseError> for CoreError
Source§fn from(err: CslParseError) -> Self
fn from(err: CslParseError) -> Self
Converts to this type from the input type.
Source§impl PartialEq for CslParseError
impl PartialEq for CslParseError
impl Eq for CslParseError
impl StructuralPartialEq for CslParseError
Auto Trait Implementations§
impl Freeze for CslParseError
impl RefUnwindSafe for CslParseError
impl Send for CslParseError
impl Sync for CslParseError
impl Unpin for CslParseError
impl UnsafeUnpin for CslParseError
impl UnwindSafe for CslParseError
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