Skip to main content

SourceMap

Struct SourceMap 

Source
pub struct SourceMap {
    pub version: u8,
    pub sources: Vec<String>,
    pub sources_content: Vec<Option<String>>,
    pub names: Vec<String>,
    pub mappings: String,
    pub file: Option<String>,
    pub source_root: Option<String>,
    pub sections: Vec<SourceMapSection>,
}
Expand description

Source Map v3 representation.

This is the main data structure for working with source maps. It follows the Source Map v3 specification.

Fields§

§version: u8

Version (always 3).

§sources: Vec<String>

List of source file paths.

§sources_content: Vec<Option<String>>

List of source file contents (optional).

§names: Vec<String>

List of symbol names.

§mappings: String

Encoded mappings string.

§file: Option<String>

Output file path (optional).

§source_root: Option<String>

Source root (optional).

§sections: Vec<SourceMapSection>

Source map references (for indexed source maps).

Implementations§

Source§

impl SourceMap

Source

pub fn new() -> Self

Creates a new empty source map.

Source

pub fn parse(json: impl Into<SourceMapInput>) -> Result<Self>

Parses a source map from JSON.

Source

pub fn to_json(&self) -> Result<String>

Converts the source map to JSON.

Source

pub fn to_json_pretty(&self) -> Result<String>

Converts the source map to pretty-printed JSON.

Source

pub fn add_source(&mut self, source: impl Into<String>) -> usize

Adds a source file.

Source

pub fn add_name(&mut self, name: impl Into<String>) -> usize

Adds a name.

Source

pub fn set_source_content(&mut self, index: usize, content: impl Into<String>)

Sets the content for a source.

Source

pub fn get_source(&self, index: usize) -> Option<&str>

Gets the source path at an index.

Source

pub fn get_name(&self, index: usize) -> Option<&str>

Gets the name at an index.

Source

pub fn get_source_content(&self, index: usize) -> Option<Option<&String>>

Gets the source content at an index.

Source

pub fn parse_mappings(&self) -> Result<Vec<Mapping>>

Parses all mappings into a vector.

Source

pub fn metadata(&self) -> SourceMapMetadata

Returns metadata about this source map.

Source

pub fn to_inline_comment(&self) -> Result<String>

Generates the inline source map comment.

Source

pub fn to_external_comment(&self, filename: &str) -> String

Generates the external source map comment.

Source

pub fn is_indexed(&self) -> bool

Checks if this is an indexed source map.

Source

pub fn has_sources_content(&self) -> bool

Checks if this source map has sources content.

Source

pub fn get_full_source_path(&self, index: usize) -> Option<String>

Returns the full source path for a source index.

Trait Implementations§

Source§

impl Clone for SourceMap

Source§

fn clone(&self) -> SourceMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceMap

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SourceMap

Source§

fn default() -> SourceMap

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SourceMap

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SourceMap

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,