#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
- where B: ToOwned,
- <B as ToOwned>::Owned: 'a
+where
+ B: ToOwned,
+ <B as ToOwned>::Owned: 'a,
{
fn borrow(&self) -> &B {
&**self
/// let mut v: Vec<i32> = Vec::new();
/// [1, 2][..].clone_into(&mut v);
/// ```
- #[unstable(feature = "toowned_clone_into",
- reason = "recently added",
- issue = "41263")]
+ #[unstable(feature = "toowned_clone_into", reason = "recently added", issue = "41263")]
fn clone_into(&self, target: &mut Self::Owned) {
*target = self.to_owned();
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ToOwned for T
- where T: Clone
+where
+ T: Clone,
{
type Owned = T;
fn to_owned(&self) -> T {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Cow<'a, B: ?Sized + 'a>
- where B: ToOwned
+where
+ B: ToOwned,
{
/// Borrowed data.
#[stable(feature = "rust1", since = "1.0.0")]
- Borrowed(#[stable(feature = "rust1", since = "1.0.0")]
- &'a B),
+ Borrowed(#[stable(feature = "rust1", since = "1.0.0")] &'a B),
/// Owned data.
#[stable(feature = "rust1", since = "1.0.0")]
- Owned(#[stable(feature = "rust1", since = "1.0.0")]
- <B as ToOwned>::Owned),
+ Owned(#[stable(feature = "rust1", since = "1.0.0")] <B as ToOwned>::Owned),
}
#[stable(feature = "rust1", since = "1.0.0")]
}
fn clone_from(&mut self, source: &Self) {
- if let Owned(ref mut dest) = *self {
- if let Owned(ref o) = *source {
- o.borrow().clone_into(dest);
- return;
- }
+ match (self, source) {
+ (&mut Owned(ref mut dest), &Owned(ref o)) => o.borrow().clone_into(dest),
+ (t, s) => *t = s.clone(),
}
-
- *self = source.clone();
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<B: ?Sized> Ord for Cow<'_, B>
- where B: Ord + ToOwned
+where
+ B: Ord + ToOwned,
{
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B>
- where B: PartialEq<C> + ToOwned,
- C: ToOwned
+where
+ B: PartialEq<C> + ToOwned,
+ C: ToOwned,
{
#[inline]
fn eq(&self, other: &Cow<'b, C>) -> bool {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> PartialOrd for Cow<'a, B>
- where B: PartialOrd + ToOwned
+where
+ B: PartialOrd + ToOwned,
{
#[inline]
fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<B: ?Sized> Hash for Cow<'_, B>
- where B: Hash + ToOwned
+where
+ B: Hash + ToOwned,
{
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
fn add_assign(&mut self, rhs: &'a str) {
if self.is_empty() {
*self = Cow::Borrowed(rhs)
- } else if rhs.is_empty() {
- return;
- } else {
+ } else if !rhs.is_empty() {
if let Cow::Borrowed(lhs) = *self {
let mut s = String::with_capacity(lhs.len() + rhs.len());
s.push_str(lhs);
fn add_assign(&mut self, rhs: Cow<'a, str>) {
if self.is_empty() {
*self = rhs
- } else if rhs.is_empty() {
- return;
- } else {
+ } else if !rhs.is_empty() {
if let Cow::Borrowed(lhs) = *self {
let mut s = String::with_capacity(lhs.len() + rhs.len());
s.push_str(lhs);