pub struct Location { /* private fields */ }Expand description
Row/column location within the source YAML document (1-indexed, character-based).
This type is used for both:
- deserialization error reporting ([
crate::Error]) - span-aware values (
crate::Spanned)
§Example
use serde::Deserialize;
#[derive(Deserialize, Debug)]
struct Doc {
val: String,
}
// 1. Parse invalid YAML (type mismatch: expected string, found sequence)
// Due emoji character and byte offsets are different.
let yaml = "val🔑: [1, 2]";
let err: Result<Doc, _> = serde_saphyr::from_str(yaml);
// 2. Obtain the error and its location
if let Err(e) = err {
if let Some(loc) = e.location() {
// 3. Print row, column, and byte offsets
// Output: Error at line 1, col 7. Byte offset: 9
println!("Error at line {}, col {}", loc.line(), loc.column());
if let Some(byte_off) = loc.span().byte_offset() {
println!("Byte offset: {}", byte_off);
}
}
}Implementations§
Trait Implementations§
impl Copy for Location
Source§impl<'de> Deserialize<'de> for Location
impl<'de> Deserialize<'de> for Location
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Location
impl StructuralPartialEq for Location
Auto Trait Implementations§
impl Freeze for Location
impl RefUnwindSafe for Location
impl Send for Location
impl Sync for Location
impl Unpin for Location
impl UnsafeUnpin for Location
impl UnwindSafe for Location
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