Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add impl AddAssign<char> for Cow<'_, str> #66215

Closed
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/liballoc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,15 @@ impl<'a> AddAssign<Cow<'a, str>> for Cow<'a, str> {
}
}
}

#[stable(feature = "cow_str_add_assign_char", since = "1.41.0")]
impl AddAssign<char> for Cow<'_, str> {
Ruster-a11y marked this conversation as resolved.
Show resolved Hide resolved
fn add_assign(&mut self, rhs: char) {
if let Cow::Borrowed(lhs) = *self {
let mut s = String::with_capacity(lhs.len() + rhs.len_utf8());
Ruster-a11y marked this conversation as resolved.
Show resolved Hide resolved
s.push_str(lhs);
*self = Cow::Owned(s);
}
self.to_mut().push(rhs);
}
}
Ruster-a11y marked this conversation as resolved.
Show resolved Hide resolved
dtolnay marked this conversation as resolved.
Show resolved Hide resolved