Struct rspack_sources::ConcatSource

source ·
pub struct ConcatSource { /* private fields */ }
Expand description

Concatenate multiple Sources to a single Source.

use rspack_sources::{
  BoxSource, ConcatSource, MapOptions, OriginalSource, RawSource, Source,
  SourceExt, SourceMap,
};

let mut source = ConcatSource::new([
  RawSource::from("Hello World\n".to_string()).boxed(),
  OriginalSource::new(
    "console.log('test');\nconsole.log('test2');\n",
    "console.js",
  )
  .boxed(),
]);
source.add(OriginalSource::new("Hello2\n", "hello.md"));

assert_eq!(source.size(), 62);
assert_eq!(
  source.source(),
  "Hello World\nconsole.log('test');\nconsole.log('test2');\nHello2\n"
);
assert_eq!(
  source.map(&MapOptions::new(false)).unwrap(),
  SourceMap::from_json(
    r#"{
      "version": 3,
      "mappings": ";AAAA;AACA;ACDA",
      "names": [],
      "sources": ["console.js", "hello.md"],
      "sourcesContent": [
        "console.log('test');\nconsole.log('test2');\n",
        "Hello2\n"
      ]
    }"#,
  )
  .unwrap()
);

Implementations§

source§

impl ConcatSource

source

pub fn new<S, T>(sources: S) -> Self
where T: Source + 'static, S: IntoIterator<Item = T>,

Create a ConcatSource with Sources.

source

pub fn add<S: Source + 'static>(&mut self, source: S)

Add a Source to concat.

Trait Implementations§

source§

impl Clone for ConcatSource

source§

fn clone(&self) -> ConcatSource

Returns a copy 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 ConcatSource

source§

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

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

impl Default for ConcatSource

source§

fn default() -> ConcatSource

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

impl Hash for ConcatSource

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for ConcatSource

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Source for ConcatSource

source§

fn source(&self) -> Cow<'_, str>

Get the source code.
source§

fn buffer(&self) -> Cow<'_, [u8]>

Get the source buffer.
source§

fn size(&self) -> usize

Get the size of the source.
source§

fn map(&self, options: &MapOptions) -> Option<SourceMap>

Get the SourceMap.
source§

fn to_writer(&self, writer: &mut dyn Write) -> Result<()>

Writes the source into a writer, preferably a std::io::BufWriter<std::io::Write>.
source§

fn update_hash(&self, state: &mut dyn Hasher)

Update hash based on the source.
source§

impl StreamChunks for ConcatSource

source§

fn stream_chunks( &self, options: &MapOptions, on_chunk: OnChunk<'_>, on_source: OnSource<'_>, on_name: OnName<'_>, ) -> GeneratedInfo

StreamChunks abstraction
source§

impl Eq for ConcatSource

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> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> SourceExt for T
where T: Source + 'static,

source§

fn boxed(self) -> Arc<dyn Source>

An alias for BoxSource::from.
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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.