Skip to content

Commit ddb7718

Browse files
author
Jorge Aparicio
committed
impl Clone for Cow
1 parent 82fc1aa commit ddb7718

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libcore/borrow.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ pub enum Cow<'a, T, Sized? B: 'a> where B: ToOwned<T> {
137137
Owned(T)
138138
}
139139

140+
impl<'a, T, Sized? B> Clone for Cow<'a, T, B> where B: ToOwned<T> {
141+
fn clone(&self) -> Cow<'a, T, B> {
142+
match *self {
143+
Borrowed(b) => Borrowed(b),
144+
Owned(ref o) => {
145+
let b: &B = BorrowFrom::borrow_from(o);
146+
Owned(b.to_owned())
147+
},
148+
}
149+
}
150+
}
151+
140152
impl<'a, T, Sized? B> Cow<'a, T, B> where B: ToOwned<T> {
141153
/// Acquire a mutable reference to the owned form of the data.
142154
///

0 commit comments

Comments
 (0)