Skip to main content

Range

Struct Range 

Source
#[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 onlyorigin_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
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.
§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

Source

pub fn new(span: ByteRange<usize>, start: Position, end: Position) -> Self

Source

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.

Source

pub fn origin(&self) -> Option<&Path>

Borrow the origin path, if any.

Source

pub fn contains(&self, pos: Position) -> bool

Check if a position is contained within this location

Source

pub fn overlaps(&self, other: &Range) -> bool

Check if another location overlaps with this location

Source

pub fn bounding_box<'a, I>(ranges: I) -> Option<Range>
where I: Iterator<Item = &'a 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 Clone for Range

Source§

fn clone(&self) -> Range

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Range

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Range

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Range

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Range

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Range

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Range

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Range

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,