Enum nondestructive::yaml::ErrorKind
source · pub enum ErrorKind {
ExpectedEof,
BadSequenceTerminator,
BadMappingSeparator,
BadMappingTerminator,
BadEscape,
BadHexEscape,
BadUnicodeEscape,
}
Expand description
The kind of an Error
.
Variants§
ExpectedEof
Expect end of file.
§Examples
use anyhow::Context;
use nondestructive::yaml;
const INPUT: &str = r#"
{hello: world}
42
"#;
let error = yaml::from_slice(INPUT).unwrap_err();
assert_eq!(*error.kind(), yaml::ErrorKind::ExpectedEof);
assert_eq!(&INPUT[error.span()], "42\n");
BadSequenceTerminator
Bad a sequence terminator.
§Examples
use nondestructive::yaml;
const INPUT: &str = r#"[Aristotle, # this is a comment"#;
let error = yaml::from_slice(INPUT).unwrap_err();
assert_eq!(*error.kind(), yaml::ErrorKind::BadSequenceTerminator);
assert_eq!(&INPUT[error.span()], " # this is a comment");
BadMappingSeparator
Bad mapping separator.
§Examples
use nondestructive::yaml;
const INPUT: &str = r#"{name: Aristotle, age # this is a comment"#;
let error = yaml::from_slice(INPUT).unwrap_err();
assert_eq!(*error.kind(), yaml::ErrorKind::BadMappingSeparator);
assert_eq!(&INPUT[error.span()], " age # this is a comment");
Missing terminator in a non-inline mapping:
use nondestructive::yaml;
const INPUT: &str = r#"
name: Aristotle
age # end"#;
let error = yaml::from_slice(INPUT).unwrap_err();
assert_eq!(*error.kind(), yaml::ErrorKind::BadMappingSeparator);
assert_eq!(&INPUT[error.span()], "age # end");
BadMappingTerminator
Bad a mapping terminator.
§Examples
use nondestructive::yaml;
const INPUT: &str = r#"{name: Aristotle, # this is a comment"#;
let error = yaml::from_slice(INPUT).unwrap_err();
assert_eq!(*error.kind(), yaml::ErrorKind::BadMappingTerminator);
assert_eq!(&INPUT[error.span()], " # this is a comment");
BadEscape
Not a valid escape sequence.
§Examples
use nondestructive::yaml;
const INPUT: &str = r#""hello \o1u world""#;
let error = yaml::from_slice(INPUT).unwrap_err();
assert_eq!(*error.kind(), yaml::ErrorKind::BadEscape);
assert_eq!(&INPUT[error.span()], "\\o");
BadHexEscape
Bad hex escape.
§Examples
use nondestructive::yaml;
const INPUT: &str = r#""hello \x1u world""#;
let error = yaml::from_slice(INPUT).unwrap_err();
assert_eq!(*error.kind(), yaml::ErrorKind::BadHexEscape);
assert_eq!(&INPUT[error.span()], "\\x1u");
BadUnicodeEscape
Bad unicode escape.
§Examples
use nondestructive::yaml;
const INPUT: &str = r#""hello \ud800 world""#;
let error = yaml::from_slice(INPUT).unwrap_err();
assert_eq!(*error.kind(), yaml::ErrorKind::BadUnicodeEscape);
assert_eq!(&INPUT[error.span()], "\\ud800");
Trait Implementations§
source§impl PartialEq for ErrorKind
impl PartialEq for ErrorKind
impl Eq for ErrorKind
impl StructuralPartialEq for ErrorKind
Auto Trait Implementations§
impl Freeze for ErrorKind
impl RefUnwindSafe for ErrorKind
impl Send for ErrorKind
impl Sync for ErrorKind
impl Unpin for ErrorKind
impl UnwindSafe for ErrorKind
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