Struct rspack_sources::ReplaceSource

source ·
pub struct ReplaceSource<T> { /* private fields */ }
Expand description

Decorates a Source with replacements and insertions of source code, usually used in dependencies

use rspack_sources::{OriginalSource, ReplaceSource, Source};

let code = "hello world\n";
let mut source = ReplaceSource::new(OriginalSource::new(code, "file.txt"));

source.insert(0, "start1\n", None);
source.replace(0, 0, "start2\n", None);
source.replace(999, 10000, "end2", None);
source.insert(888, "end1\n", None);
source.replace(0, 999, "replaced!\n", Some("whole"));

assert_eq!(source.source(), "start1\nstart2\nreplaced!\nend1\nend2");

Implementations§

source§

impl<T> ReplaceSource<T>

source

pub fn new(source: T) -> Self

Create a ReplaceSource.

source

pub fn original(&self) -> &T

Get the original Source.

source§

impl<T: Source> ReplaceSource<T>

source

pub fn insert(&mut self, start: u32, content: &str, name: Option<&str>)

Insert a content at start.

source

pub fn replace( &mut self, start: u32, end: u32, content: &str, name: Option<&str>, )

Create a replacement with content at [start, end).

Trait Implementations§

source§

impl<T: Source> Clone for ReplaceSource<T>

source§

fn clone(&self) -> Self

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<T: Debug> Debug for ReplaceSource<T>

source§

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

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

impl<T: Hash> Hash for ReplaceSource<T>

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<T: PartialEq> PartialEq for ReplaceSource<T>

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<T: Source + Hash + PartialEq + Eq + 'static> Source for ReplaceSource<T>

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<T: Source> StreamChunks for ReplaceSource<T>

source§

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

StreamChunks abstraction
source§

impl<T: Eq> Eq for ReplaceSource<T>

Auto Trait Implementations§

§

impl<T> !Freeze for ReplaceSource<T>

§

impl<T> RefUnwindSafe for ReplaceSource<T>
where T: RefUnwindSafe,

§

impl<T> Send for ReplaceSource<T>
where T: Sync + Send,

§

impl<T> Sync for ReplaceSource<T>
where T: Sync + Send,

§

impl<T> Unpin for ReplaceSource<T>

§

impl<T> UnwindSafe for ReplaceSource<T>
where T: RefUnwindSafe,

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.