pub struct SourceOffset(/* private fields */);
Expand description
Newtype that represents the ByteOffset
from the beginning of a SourceCode
Implementations§
Source§impl SourceOffset
impl SourceOffset
Sourcepub const fn offset(&self) -> ByteOffset
pub const fn offset(&self) -> ByteOffset
Actual byte offset.
Sourcepub fn from_location(
source: impl AsRef<str>,
loc_line: usize,
loc_col: usize,
) -> Self
pub fn from_location( source: impl AsRef<str>, loc_line: usize, loc_col: usize, ) -> Self
Little utility to help convert 1-based line/column locations into miette-compatible Spans
This function is infallible: Giving an out-of-range line/column pair will return the offset of the last byte in the source.
Sourcepub fn from_current_location() -> Result<(String, Self), MietteError>
pub fn from_current_location() -> Result<(String, Self), MietteError>
Returns an offset for the file location of wherever this function is
called. If you want to get that caller’s location, mark this
function’s caller with #[track_caller]
(and so on and so forth).
Returns both the filename that was given and the offset of the caller
as a SourceOffset
.
Keep in mind that this fill only work if the file your Rust source file was compiled from is actually available at that location. If you’re shipping binaries for your application, you’ll want to ignore the Err case or otherwise report it.
Trait Implementations§
Source§impl Clone for SourceOffset
impl Clone for SourceOffset
Source§fn clone(&self) -> SourceOffset
fn clone(&self) -> SourceOffset
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more