From ddb77185d36985aeac85094cb4742da93a7e821d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 27 Nov 2014 09:04:20 -0500 Subject: [PATCH] impl Clone for Cow --- src/libcore/borrow.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libcore/borrow.rs b/src/libcore/borrow.rs index 06fda8d60928f..0bfa3dac1b0ee 100644 --- a/src/libcore/borrow.rs +++ b/src/libcore/borrow.rs @@ -137,6 +137,18 @@ pub enum Cow<'a, T, Sized? B: 'a> where B: ToOwned { Owned(T) } +impl<'a, T, Sized? B> Clone for Cow<'a, T, B> where B: ToOwned { + fn clone(&self) -> Cow<'a, T, B> { + match *self { + Borrowed(b) => Borrowed(b), + Owned(ref o) => { + let b: &B = BorrowFrom::borrow_from(o); + Owned(b.to_owned()) + }, + } + } +} + impl<'a, T, Sized? B> Cow<'a, T, B> where B: ToOwned { /// Acquire a mutable reference to the owned form of the data. ///