pub struct ConcatSource { /* private fields */ }Expand description
Concatenate multiple Sources to a single Source.
use rspack_sources::{
BoxSource, ConcatSource, MapOptions, OriginalSource, RawStringSource, Source,
SourceExt, SourceMap, ObjectPool
};
let mut source = ConcatSource::new([
RawStringSource::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().into_string_lossy(),
"Hello World\nconsole.log('test');\nconsole.log('test2');\nHello2\n"
);
assert_eq!(
source.map(&ObjectPool::default(), &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
impl ConcatSource
Sourcepub fn new<S, T>(sources: S) -> Selfwhere
T: Source + 'static,
S: IntoIterator<Item = T>,
pub fn new<S, T>(sources: S) -> Selfwhere
T: Source + 'static,
S: IntoIterator<Item = T>,
Create a ConcatSource with Sources.
Trait Implementations§
Source§impl Clone for ConcatSource
impl Clone for ConcatSource
Source§impl Debug for ConcatSource
impl Debug for ConcatSource
Source§impl Default for ConcatSource
impl Default for ConcatSource
Source§fn default() -> ConcatSource
fn default() -> ConcatSource
Returns the “default value” for a type. Read more
Source§impl Hash for ConcatSource
impl Hash for ConcatSource
Source§impl PartialEq for ConcatSource
impl PartialEq for ConcatSource
Source§impl Source for ConcatSource
impl Source for ConcatSource
Source§fn source(&self) -> SourceValue<'_>
fn source(&self) -> SourceValue<'_>
Get the source code.
Source§fn rope<'a>(&'a self, on_chunk: &mut dyn FnMut(&'a str))
fn rope<'a>(&'a self, on_chunk: &mut dyn FnMut(&'a str))
Return a lightweight “rope” view of the source as borrowed string slices.
Source§fn map<'a>(
&'a self,
object_pool: &'a ObjectPool,
options: &MapOptions,
) -> Option<SourceMap>
fn map<'a>( &'a self, object_pool: &'a ObjectPool, options: &MapOptions, ) -> Option<SourceMap>
Get the SourceMap.
Source§fn to_writer(&self, writer: &mut dyn Write) -> Result<()>
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)
fn update_hash(&self, state: &mut dyn Hasher)
Update hash based on the source.
Source§impl StreamChunks for ConcatSource
impl StreamChunks for ConcatSource
Source§fn stream_chunks<'a>(&'a self) -> Box<dyn Chunks + 'a>
fn stream_chunks<'a>(&'a self) -> Box<dyn Chunks + 'a>
StreamChunks abstraction
impl Eq for ConcatSource
Auto Trait Implementations§
impl !Freeze for ConcatSource
impl !RefUnwindSafe for ConcatSource
impl Send for ConcatSource
impl Sync for ConcatSource
impl Unpin for ConcatSource
impl !UnwindSafe for ConcatSource
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.