Skip to content

Commit 9525af7

Browse files
committed
rollup merge of #19359: japaric/clone-cow
Now we can use `#[deriving(Clone)]` on structs that contain `Cow`. r? @aturon or anyone else
2 parents 08ce178 + ddb7718 commit 9525af7

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)