pub struct Span { /* private fields */ }Expand description
Represents a contiguous segment of source code.
start and end are byte offsets into the source code,
while line and column represent the human-readable
position of the span.
This structure can be used for highlighting errors, diagnostics,
or feeding external crates like ariadne.
§Example
use rhai_trace::Span;
let span = Span::new(10, 20, 2, 5);
println!("Span covers bytes {}..{} on line {}", span.start(), span.end(), span.line());Implementations§
Source§impl Span
impl Span
Sourcepub fn new(start: usize, end: usize, line: usize, column: usize) -> Self
pub fn new(start: usize, end: usize, line: usize, column: usize) -> Self
Creates a new Span from byte offsets, line, and column.
Sourcepub fn from_pos(script: &str, pos: &Position) -> Self
pub fn from_pos(script: &str, pos: &Position) -> Self
Creates a Span from a Rhai Position and the script text.
Computes byte offsets based on line and column.
Sourcepub fn from_rhai_start_end_pos(
script: &str,
start: &Position,
end: &Position,
) -> Self
pub fn from_rhai_start_end_pos( script: &str, start: &Position, end: &Position, ) -> Self
Creates a Span from Rhai start and end Positions.
Sourcepub fn from_rhai_span(script: &str, rhai_span: Span, pos: &Position) -> Self
pub fn from_rhai_span(script: &str, rhai_span: Span, pos: &Position) -> Self
Converts a Rhai Span to our Span type using a reference Position.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
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> Variant for T
impl<T> Variant for T
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert this
Variant trait object to &mut dyn Any.Source§fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
Convert this
Variant trait object to Box<dyn Any>.