Replacer

Struct Replacer 

Source
pub struct Replacer<'a> { /* private fields */ }
Expand description

Replacer replaces a list of slices with replacements. It is safe for concurrent use by multiple goroutines.

zh-cn Replacer类型进行一系列字节切片的替换。

Implementations§

Source§

impl<'a> Replacer<'a>

Source

pub fn new(pairs: Vec<(&'a [byte], &'a [byte])>) -> Replacer<'a>

new returns a new Replacer from a list of old, new bytes pairs. Replacements are performed in the order they appear in the target string, without overlapping matches. The old string comparisons are done in argument order.

zh-cn 使用提供的多组old、new字节切片对创建并返回一个*Replacer。替换是依次进行的,匹配时不会重叠。
§Example
use gostd_bytes as bytes;

   let p = vec![("<".as_bytes(), "&lt;".as_bytes()), (">".as_bytes(), "&gt;".as_bytes())];
   let r = bytes::Replacer::new(p);
   let s = r.Replace("This is <b>HTML</b>!".as_bytes());
   println!("{}", String::from_utf8(s).unwrap());
§Output
This is &lt;b&gt;HTML&lt;/b&gt;!
Source

pub fn Replace(self, s: &[byte]) -> Vec<byte>

Replace returns a copy of s with all replacements performed.

zh-cn Replace返回s的所有替换进行完后的拷贝.
Source

pub fn WriteString(&self, w: Box<dyn Writer>, s: &str) -> Result<int, Error>

WriteString writes s to w with all replacements performed.

zh-cn WriteString向w中写入s的所有替换进行完后的拷贝

Auto Trait Implementations§

§

impl<'a> Freeze for Replacer<'a>

§

impl<'a> RefUnwindSafe for Replacer<'a>

§

impl<'a> Send for Replacer<'a>

§

impl<'a> Sync for Replacer<'a>

§

impl<'a> Unpin for Replacer<'a>

§

impl<'a> UnwindSafe for Replacer<'a>

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