pub struct Location {
pub line: NonZero<u32>,
pub col: u32,
}Expand description
Location of the error. Useful for error reporting, and used by crate::FullParsingError
Fields§
§line: NonZero<u32>Source code line of the location.
col: u32Source code column of the location.
Implementations§
Source§impl Location
impl Location
Sourcepub fn with_path<'path>(self, path: impl PathLike<'path>) -> FullLocation<'path>
pub fn with_path<'path>(self, path: impl PathLike<'path>) -> FullLocation<'path>
Turn a Location into a FullLocation by providing the file path.
Sourcepub fn find(ptr: *const u8, src: &str) -> Option<Self>
pub fn find(ptr: *const u8, src: &str) -> Option<Self>
Locates address ptr in src and returns its source code location, or None if ptr is
outside of the memory range of src.
Sourcepub fn find_saturating(ptr: *const u8, src: &str) -> Self
pub fn find_saturating(ptr: *const u8, src: &str) -> Self
Same as find, except for the None case:
- If
ptris beforesrc, the returned location points to the beginning ofsrc. - If
ptris aftersrc, the returned location points to the end ofsrc.
This function is used by crate::ParsingError::with_src_loc
Sourcepub fn find_in_multiple<K>(
ptr: *const u8,
files: impl IntoIterator<Item = (K, impl AsRef<str>)>,
) -> Option<(K, Self)>
pub fn find_in_multiple<K>( ptr: *const u8, files: impl IntoIterator<Item = (K, impl AsRef<str>)>, ) -> Option<(K, Self)>
Same as find, but searches in multiple “files”.
A file, per definition of this function, is a key K that identifies it,
and a memory range that is its content.
The function returns the key of the file where ptr is contained, or None if no files
matched.
use std::collections::HashMap;
use shrimple_parser::{Location, nonzero, tuple::copied};
let file2 = " \n\nfn main() { panic!() }";
let sources = HashMap::from([
("file1.rs", r#"fn main() { println!("Hiiiii!!!!! :3") }"#),
("file2.rs", file2),
]);
let no_ws = file2.trim();
assert_eq!(
Location::find_in_multiple(no_ws.as_ptr(), sources.iter().map(copied)),
Some(("file2.rs", Location { line: nonzero!(3), col: 0 })),
)Also see [tuple::copied], nonzero
Trait Implementations§
Source§impl From<Location> for LineColumn
Available on crate feature proc-macro2 only.
impl From<Location> for LineColumn
Available on crate feature
proc-macro2 only.Source§impl Ord for Location
impl Ord for Location
Source§impl PartialOrd for Location
impl PartialOrd for Location
Source§impl TryFrom<LineColumn> for Location
Available on crate feature proc-macro2 only.
impl TryFrom<LineColumn> for Location
Available on crate feature
proc-macro2 only.Source§type Error = LineColumnToLocationError
type Error = LineColumnToLocationError
The type returned in the event of a conversion error.
impl Copy for Location
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more