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 moresource§impl Debug for SourceOffset
impl Debug for SourceOffset
source§impl From<SourceOffset> for SourceSpan
impl From<SourceOffset> for SourceSpan
source§fn from(offset: SourceOffset) -> Self
fn from(offset: SourceOffset) -> Self
source§impl From<usize> for SourceOffset
impl From<usize> for SourceOffset
source§fn from(bytes: ByteOffset) -> Self
fn from(bytes: ByteOffset) -> Self
source§impl Hash for SourceOffset
impl Hash for SourceOffset
source§impl Ord for SourceOffset
impl Ord for SourceOffset
source§fn cmp(&self, other: &SourceOffset) -> Ordering
fn cmp(&self, other: &SourceOffset) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for SourceOffset
impl PartialEq for SourceOffset
source§impl PartialOrd for SourceOffset
impl PartialOrd for SourceOffset
impl Copy for SourceOffset
impl Eq for SourceOffset
impl StructuralPartialEq for SourceOffset
Auto Trait Implementations§
impl Freeze for SourceOffset
impl RefUnwindSafe for SourceOffset
impl Send for SourceOffset
impl Sync for SourceOffset
impl Unpin for SourceOffset
impl UnwindSafe for SourceOffset
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)