pub struct SourceMapBuilder { /* private fields */ }
Expand description

Helper for sourcemap generation

This helper exists because generating and modifying SourceMap objects is generally not very comfortable. As a general aid this type can help.

Implementations§

source§

impl SourceMapBuilder

source

pub fn new(file: Option<&str>) -> SourceMapBuilder

Creates a new source map builder and sets the file.

source

pub fn set_debug_id(&mut self, debug_id: Option<DebugId>)

Sets the debug id for the sourcemap (optional)

source

pub fn set_file<T: Into<String>>(&mut self, value: Option<T>)

Sets the file for the sourcemap (optional)

source

pub fn get_file(&self) -> Option<&str>

Returns the currently set file.

source

pub fn set_source_root<T: Into<String>>(&mut self, value: Option<T>)

Sets a new value for the source_root.

source

pub fn get_source_root(&self) -> Option<&str>

Returns the embedded source_root in case there is one.

source

pub fn add_source(&mut self, src: &str) -> u32

Registers a new source with the builder and returns the source ID.

source

pub fn set_source(&mut self, src_id: u32, src: &str)

Changes the source name for an already set source.

source

pub fn get_source(&self, src_id: u32) -> Option<&str>

Looks up a source name for an ID.

source

pub fn set_source_contents(&mut self, src_id: u32, contents: Option<&str>)

Sets the source contents for an already existing source.

source

pub fn get_source_contents(&self, src_id: u32) -> Option<&str>

Returns the current source contents for a source.

source

pub fn has_source_contents(&self, src_id: u32) -> bool

Checks if a given source ID has source contents available.

source

pub fn load_local_source_contents( &mut self, base_path: Option<&Path> ) -> Result<usize>

Loads source contents from locally accessible files if referenced accordingly. Returns the number of loaded source contents

source

pub fn add_name(&mut self, name: &str) -> u32

Registers a name with the builder and returns the name ID.

source

pub fn add( &mut self, dst_line: u32, dst_col: u32, src_line: u32, src_col: u32, source: Option<&str>, name: Option<&str> ) -> RawToken

Adds a new mapping to the builder.

source

pub fn add_raw( &mut self, dst_line: u32, dst_col: u32, src_line: u32, src_col: u32, source: Option<u32>, name: Option<u32> ) -> RawToken

Adds a new mapping to the builder.

source

pub fn add_token(&mut self, token: &Token<'_>, with_name: bool) -> RawToken

Shortcut for adding a new mapping based of an already existing token, optionally removing the name.

source

pub fn strip_prefixes<S: AsRef<str>>(&mut self, prefixes: &[S])

Strips common prefixes from the sources in the builder

source

pub fn into_sourcemap(self) -> SourceMap

Converts the builder into a sourcemap.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.