#[non_exhaustive]pub struct Range {
pub span: Range<usize>,
pub start: Position,
pub end: Position,
pub origin_path: Option<Arc<PathBuf>>,
}Expand description
Represents a location in source code (start and end positions)
Carries an optional origin_path identifying the source file the range refers
to. For ranges built directly by the parser this is None; ranges produced
by include resolution (lex_core::includes) carry the canonical path of the
file they came from. The field is metadata: it does not affect parsing,
formatting, or any structural operation, but it is consulted by file-reference
resolution and diagnostics so that information attached to nodes from an
included file points at the authoring location, not the post-merge one.
Range is #[non_exhaustive]: external code must construct via Range::new
(or builders such as with_origin) rather than struct literals, so future
metadata fields can be added without a breaking API change.
Equality and hashing are positional only — origin_path is intentionally
excluded from PartialEq/Hash. Two ranges with the same span and positions
are equal regardless of which file they came from. This matches what is
preserved through serde (origin_path is #[serde(skip)]), so a value can
round-trip through JSON without breaking equality.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.span: Range<usize>§start: Position§end: Position§origin_path: Option<Arc<PathBuf>>Optional path of the file this range was authored in.
None for ranges that have not been touched by include resolution.
Currently skipped from (de)serialization because Arc<T> deserialization
requires serde’s opt-in rc feature; the field is metadata and is not
part of any wire format today. When a use case needs origin info on the
wire, switch to a custom (de)serialization that emits the path as a
string.
Implementations§
Source§impl Range
impl Range
pub fn new(span: ByteRange<usize>, start: Position, end: Position) -> Self
Sourcepub fn with_origin(self, path: Arc<PathBuf>) -> Self
pub fn with_origin(self, path: Arc<PathBuf>) -> Self
Builder: attach an origin path to this range.
Intended use: the include resolver, after parsing each loaded file,
walks the resulting tree and stamps the file’s canonical path on every
range. Direct parser output should leave this None.
Sourcepub fn contains(&self, pos: Position) -> bool
pub fn contains(&self, pos: Position) -> bool
Check if a position is contained within this location
Sourcepub fn overlaps(&self, other: &Range) -> bool
pub fn overlaps(&self, other: &Range) -> bool
Check if another location overlaps with this location
Sourcepub fn bounding_box<'a, I>(ranges: I) -> Option<Range>
pub fn bounding_box<'a, I>(ranges: I) -> Option<Range>
Build a bounding box that contains all provided ranges.
The result’s origin_path is Some(p) only when every input range
shares the same origin p; mixed-origin inputs (or any None mixed
with Some) yield None. This avoids reporting one file’s origin on
coordinates that came from another file — relevant after include
resolution, when a parent node may aggregate children from the host
file and from spliced-in files.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Range
impl<'de> Deserialize<'de> for Range
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>,
impl Eq for Range
Auto Trait Implementations§
impl Freeze for Range
impl RefUnwindSafe for Range
impl Send for Range
impl Sync for Range
impl Unpin for Range
impl UnsafeUnpin for Range
impl UnwindSafe for Range
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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