Trait SimpleTransform

Source
pub trait SimpleTransform<'a>: Iterator<Item = char> + Sized {
    // Required method
    fn transform_chars(chars: Chars<'a>) -> Self;

    // Provided methods
    fn will_modify(val: &str) -> bool { ... }
    fn transform<'b, T: Into<Cow<'b, str>>>(s: T) -> Cow<'b, str> { ... }
}
Expand description

A simple trait for in-place string transformations.

This trait allows character-iterator adaptors to modify strings in-place. It is implemented by adaptors with a single required associated function, transform_chars, for constructing the adaptor. In return, this trait provides an associated function, transform, which can apply the transformation to both owned strings and string slices, without allocating when possible.

This trait is a simplified version of StringTransform. See the documentation of that trait for more details.

Required Methods§

Source

fn transform_chars(chars: Chars<'a>) -> Self

Transform the characters of a string.

Provided Methods§

Source

fn will_modify(val: &str) -> bool

A hint to short-circuit string transformations.

If true, the string might be modified by the transform. If false, the string will definitely not be modified by the transform.

Implementors may override this function to facilitate copy-on-write optimizations. The default implementation always returns true, which disables copy-on-write.

Source

fn transform<'b, T: Into<Cow<'b, str>>>(s: T) -> Cow<'b, str>

Transform a string in-place

This function can operate on both String and &str.

A new string may be allocated if the input is not owned or if the transformation needs to buffer more characters than the string has capacity.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§