Previously, FormattedStringExt::strip_formatting always copied whole string even if its return type is Cow<'_, str>. Its method signature prevents the impl for String to reuse self because there is no way to take the ownership from the caller.
For this reason, I have to change the interface of FormattedStringExt trait. Theoretically it is backward-incompatible, but I think it's critical only if this trait was implemented in the outside.
Instead the new implementation gains the benefit of memory usages. for str, stripping will be almost no-op for unformatted text. And for String, it will allocate no additional memory in most of cases.
Sorry for the delay in review! I've been very busy as of late, and wanted to give this a good look through. Thanks for the contribution! I love the little test macro. 😄
It also fixes infinite recursion described in https://github.com/aatxe/irc/pull/137#issuecomment-414094604.
Previously,
FormattedStringExt::strip_formatting
always copied whole string even if its return type isCow<'_, str>
. Its method signature prevents the impl forString
to reuseself
because there is no way to take the ownership from the caller.For this reason, I have to change the interface of
FormattedStringExt
trait. Theoretically it is backward-incompatible, but I think it's critical only if this trait was implemented in the outside.Instead the new implementation gains the benefit of memory usages. for
str
, stripping will be almost no-op for unformatted text. And forString
, it will allocate no additional memory in most of cases.