You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We often have to trim strings because some values contain superfluous whitespace while most values do not. To avoid reallocating a new string for the majority of the values, we currently use a little extension trait called TrimExt with works like
implTrimExtforString{fntrim(self) -> Self{let val = self.as_str().trim();if val.len() != self.len(){
val.to_owned()}else{self}}}
i.e. it keeps to original value if the trimming is actually a no-op.
So this does not really fit into the CowUtils trait as far I can see, but I think one could say that it does fit with this crate's aim of avoiding allocations when no modifications are necessary.
Would you be interested in adding a new trait to capture this problem which I think is sort of a converse to the replace problem, i.e. we start with an owned value and want to keep it if possible.
The text was updated successfully, but these errors were encountered:
We often have to trim strings because some values contain superfluous whitespace while most values do not. To avoid reallocating a new string for the majority of the values, we currently use a little extension trait called
TrimExt
with works likei.e. it keeps to original value if the trimming is actually a no-op.
So this does not really fit into the
CowUtils
trait as far I can see, but I think one could say that it does fit with this crate's aim of avoiding allocations when no modifications are necessary.Would you be interested in adding a new trait to capture this problem which I think is sort of a converse to the replace problem, i.e. we start with an owned value and want to keep it if possible.
The text was updated successfully, but these errors were encountered: