[−][src]Trait char_circle::SimpleTransform
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
fn transform_chars(chars: Chars<'a>) -> Self
Transform the characters of a string.
Provided methods
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.
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.