Self::ExpectedDigit(i) => ("expected digit", Some(i)), Self::TooManyDigits(i) => ("too many digits", Some(i)), Self::TooManyDigitsBeforeDecimalPoint(i) => {
("too many digits before decimal point", Some(i))
} Self::TooManyDigitsAfterDecimalPoint(i) => {
("too many digits after decimal point", Some(i))
} Self::TrailingDecimalPoint(i) => ("trailing decimal point", Some(i)),
Self::ExpectedStartOfDate(i) => ("expected start of date ('@')", Some(i)), Self::Rfc8941Date(i) => ("RFC 8941 does not support dates", Some(i)), Self::NonIntegerDate(i) => ("date must be an integer number of seconds", Some(i)),
Self::ExpectedStartOfDisplayString(i) => {
("expected start of display string ('%')", Some(i))
} Self::Rfc8941DisplayString(i) => ("RFC 8941 does not support display strings", Some(i)), Self::ExpectedQuote(i) => (r#"expected '"'"#, Some(i)), Self::InvalidUtf8InDisplayString(i) => ("invalid UTF-8 in display string", Some(i)), Self::InvalidDisplayStringCharacter(i) => ("invalid display string character", Some(i)), Self::UnterminatedDisplayString(i) => ("unterminated display string", Some(i)),
Self::ExpectedStartOfKey(i) => ("expected start of key ('a'-'z' or '*')", Some(i)),
}
}
}
impl fmt::Display for Repr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let (msg, index) = self.parts(); match (f.alternate(), index) {
(true, _) | (false, None) => f.write_str(msg),
(false, Some(index)) => write!(f, "{msg} at index {index}"),
}
}
}
/// An error that can occur in this crate. /// /// The most common type of error is invalid input during parsing, but others /// exist as well: /// /// - Conversion to or from bare-item types such as [`Integer`][crate::Integer] /// - Attempting to serialize an empty [list][crate::ListSerializer::finish] or /// [dictionary][crate::DictSerializer::finish] /// /// By default, the `std::fmt::Display` implementation for this type includes /// the index at which the error occurred, if any. To omit this, use the /// alternate form: /// /// ``` /// # use sfv::{visitor::Ignored, Parser}; /// let err = Parser::new("abc;0").parse_item_with_visitor(Ignored).unwrap_err(); /// /// assert_eq!(format!("{}", err), "expected start of key ('a'-'z' or '*') at index 4"); /// assert_eq!(format!("{:#}", err), "expected start of key ('a'-'z' or '*')"); /// assert_eq!(err.index(), Some(4)); /// ``` #[derive(Debug)] #[cfg_attr(test, derive(PartialEq))] pubstruct Error {
repr: Repr,
}
impl Error { /// Returns the zero-based index in the input at which the error occurred, /// if any. #[must_use] pubfn index(&self) -> Option<usize> { self.repr.parts().1
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.