usecrate::path::Path; use serde::{de, ser}; use std::error; use std::fmt::{self, Debug, Display}; use std::io; use std::result; use std::str; use std::string; use std::sync::Arc; use yaml_rust::emitter; use yaml_rust::scanner::{self, Marker, ScanError};
/// An error that happened serializing or deserializing YAML data. pubstruct Error(Box<ErrorImpl>);
/// Alias for a `Result` with the error type `serde_yaml::Error`. pubtype Result<T> = result::Result<T, Error>;
/// The input location that an error occured. #[derive(Debug)] pubstruct Location {
index: usize,
line: usize,
column: usize,
}
impl Location { /// The byte index of the error pubfn index(&self) -> usize { self.index
}
/// The line of the error pubfn line(&self) -> usize { self.line
}
/// The column of the error pubfn column(&self) -> usize { self.column
}
// This is to keep decoupled with the yaml crate #[doc(hidden)] fn from_marker(marker: &Marker) -> Self {
Location { // `col` returned from the `yaml` crate is 0-indexed but all error messages add + 1 to this value
column: marker.col() + 1,
index: marker.index(),
line: marker.line(),
}
}
}
impl Error { /// Returns the Location from the error if one exists. /// /// Not all types of errors have a location so this can return `None`. /// /// # Examples /// /// ``` /// # use serde_yaml::{Value, Error}; /// # /// // The `@` character as the first character makes this invalid yaml /// let invalid_yaml: Result<Value, Error> = serde_yaml::from_str("@invalid_yaml"); /// /// let location = invalid_yaml.unwrap_err().location().unwrap(); /// /// assert_eq!(location.line(), 1); /// assert_eq!(location.column(), 1); /// ``` pubfn location(&self) -> Option<Location> { matchself.0.as_ref() {
ErrorImpl::Message(_, Some(pos)) => Some(Location::from_marker(&pos.marker)),
ErrorImpl::Scan(scan) => Some(Location::from_marker(scan.marker())),
_ => None,
}
}
}
// Remove two layers of verbosity from the debug representation. Humans often // end up seeing this representation because it is what unwrap() shows. impl Debug for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.debug(f)
}
}
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.