Skip to main content

GeneratedOffsetLookup

Struct GeneratedOffsetLookup 

Source
pub struct GeneratedOffsetLookup<'a> { /* private fields */ }
Expand description

Converts generated UTF-8 byte offsets into source-map generated positions.

V8 coverage ranges are often reported as byte offsets in generated code, while source maps use generated line and UTF-16 column pairs. This helper builds a reusable line index for one generated asset and converts offsets before forwarding them to a source map lookup.

Implementations§

Source§

impl<'a> GeneratedOffsetLookup<'a>

Source

pub fn new(generated_source: &'a str) -> Self

Create a lookup for one generated source asset.

Source

pub fn line_count(&self) -> usize

Number of generated lines tracked by this lookup.

Source

pub fn total_bytes(&self) -> usize

Total byte length of the generated source.

Source

pub fn byte_offset_to_position( &self, byte_offset: u32, ) -> Option<GeneratedLocation>

Convert a generated UTF-8 byte offset to a 0-based line and UTF-16 column.

Returns None when the offset is out of bounds, does not fit in u32, or points into the middle of a UTF-8 code point. Offsets that point at a line terminator resolve to the end column of that line. Offsets after a line terminator resolve to column 0 of the next line.

Source

pub fn original_position_for_offset<M>( &self, source_map: &M, byte_offset: u32, ) -> Option<OriginalLocation>

Look up the original source position for a generated byte offset.

Source

pub fn byte_offsets_to_positions( &self, byte_offsets: &[u32], ) -> Option<Vec<GeneratedLocation>>

Convert multiple generated byte offsets to generated positions.

Returns None if any offset is invalid.

Source

pub fn original_positions_for_offsets<M>( &self, source_map: &M, byte_offsets: &[u32], ) -> Vec<Option<OriginalLocation>>

Look up original source positions for multiple generated byte offsets.

Trait Implementations§

Source§

impl<'a> Clone for GeneratedOffsetLookup<'a>

Source§

fn clone(&self) -> GeneratedOffsetLookup<'a>

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<'a> Debug for GeneratedOffsetLookup<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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> 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, 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.