#[non_exhaustive]#[repr(C)]pub struct ByteRange {
pub tag: u32,
pub start: u32,
pub end: u32,
}Expand description
A tagged, half-open byte range [start, end).
tag is a producer-chosen 32-bit identifier - a matching dialect
can pass a pattern_id, a decoder can pass an encoding ID, an
AST-span emitter can pass a node kind, a taint-source locator can
pass a source index. The producer decides what it means; the type
carries no domain assumption.
The struct is deliberately #[repr(C)] so FFI and backend
marshalling share one layout, and #[non_exhaustive] so future
fields (capture groups, confidence, …) can be added without
breaking the API.
§Examples
use vyre_primitives::range::ByteRange;
let r = ByteRange::new(7, 10, 20);
assert_eq!(r.tag, 7);
assert_eq!(r.start, 10);
assert_eq!(r.end, 20);
assert_eq!(r.len(), 10);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.tag: u32Producer-chosen 32-bit identifier. Not interpreted by this crate.
start: u32Inclusive byte start offset.
end: u32Exclusive byte end offset.
Implementations§
Source§impl ByteRange
impl ByteRange
Sourcepub const fn new(tag: u32, start: u32, end: u32) -> Self
pub const fn new(tag: u32, start: u32, end: u32) -> Self
Construct a range. end MUST be >= start; the assertion
catches reversed ranges in both debug and release so producers
hit the bug at the call site instead of downstream.
AUDIT_2026-04-24 F-RANGE-01: promoted debug_assert! to
assert! so release builds can’t silently accept a reversed
range (which used to cascade into len() returning 0 and
every range-containment predicate answering the wrong way).
Sourcepub const fn len(&self) -> u32
pub const fn len(&self) -> u32
Length of the range in bytes.
AUDIT_2026-04-24 F-RANGE-02: uses plain subtraction so any
reversed range triggers a panic in release. Prior
saturating_sub hid producer bugs by returning 0 for
ill-formed ranges; new()’s release-time assertion now
prevents that state from reaching here in the first place,
and the plain op gives a second fail-loud line of defense if
a caller forged a ByteRange through the public fields.
Sourcepub const fn contains(&self, other: &ByteRange) -> bool
pub const fn contains(&self, other: &ByteRange) -> bool
True when self contains other (both start and end).
Sourcepub const fn ends_before(&self, other: &ByteRange) -> bool
pub const fn ends_before(&self, other: &ByteRange) -> bool
True when self ends at or before other starts (disjoint,
self first). Mirrors the Before predicate surfaced by
scanner dialects.
Trait Implementations§
impl Copy for ByteRange
impl Eq for ByteRange
Source§impl Ord for ByteRange
impl Ord for ByteRange
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for ByteRange
impl PartialOrd for ByteRange
impl StructuralPartialEq for ByteRange
Auto Trait Implementations§
impl Freeze for ByteRange
impl RefUnwindSafe for ByteRange
impl Send for ByteRange
impl Sync for ByteRange
impl Unpin for ByteRange
impl UnsafeUnpin for ByteRange
impl UnwindSafe for ByteRange
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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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.