Skip to content

Commit 76a3b55

Browse files
committed
Added AddAssign<char> implementation for String
1 parent e8f43b7 commit 76a3b55

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/liballoc/borrow.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,18 @@ impl<'a> AddAssign<Cow<'a, str>> for Cow<'a, str> {
479479
}
480480
}
481481
}
482+
483+
impl<'a> AddAssign<char> for Cow<'a, str> {
484+
fn add_assign(&mut self, rhs: char) {
485+
if self.is_empty() {
486+
*self = rhs.to_string()
487+
} else {
488+
if let Cow::Borrowed(lhs) = *self {
489+
let mut s = String::with_capacity(lhs.len() + rhs.len_utf8());
490+
s.push_str(lhs);
491+
*self = Cow::Owned(s);
492+
}
493+
self.to_mut().push(rhs);
494+
}
495+
}
496+
}

0 commit comments

Comments
 (0)