#[non_exhaustive]pub struct Location {
pub absolute_start: usize,
pub absolute_end: usize,
pub start: Position,
pub end: Position,
}Expand description
A Location represents a location in a document.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.absolute_start: usizeThe absolute start position of the location.
absolute_end: usizeThe absolute end position of the location.
start: PositionThe start position of the location.
end: PositionThe end position of the location.
Implementations§
Source§impl Location
impl Location
Sourcepub fn validate(&self, input: &str) -> Result<(), String>
pub fn validate(&self, input: &str) -> Result<(), String>
Validates that this location satisfies all invariants.
Checks:
absolute_start <= absolute_end(valid range)absolute_end <= input.len()(within bounds)- Both offsets are on UTF-8 character boundaries
§Errors
Returned as strings for easier debugging.
Sourcepub fn shift(&mut self, parent: Option<&Location>)
pub fn shift(&mut self, parent: Option<&Location>)
Shift the start and end positions of the location by the parent location.
This is super useful to adjust the location of a block that is inside another block, like anything inside a delimiter block.
Sourcepub fn shift_inline(&mut self, parent: Option<&Location>)
pub fn shift_inline(&mut self, parent: Option<&Location>)
Shifts the location inline. We subtract 1 from the line number of the start and end to account for the fact that inlines are always in the same line as the parent calling the parsing function.
pub fn shift_line_column(&mut self, line: usize, column: usize)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Location
impl<'de> Deserialize<'de> for Location
Source§fn deserialize<D>(deserializer: D) -> Result<Location, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Location, 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 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