vec: implement DeepClone
This commit is contained in:
parent
0baa92707a
commit
20567a0c3c
@ -59,7 +59,7 @@
|
|||||||
#[warn(non_camel_case_types)];
|
#[warn(non_camel_case_types)];
|
||||||
|
|
||||||
use cast;
|
use cast;
|
||||||
use clone::Clone;
|
use clone::{Clone, DeepClone};
|
||||||
use container::{Container, Mutable};
|
use container::{Container, Mutable};
|
||||||
use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
|
use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
|
||||||
use cmp;
|
use cmp;
|
||||||
@ -2199,13 +2199,20 @@ pub fn copy_memory(dst: &mut [u8], src: &[u8], count: uint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A:Clone> Clone for ~[A] {
|
impl<A: Clone> Clone for ~[A] {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> ~[A] {
|
fn clone(&self) -> ~[A] {
|
||||||
self.iter().map(|item| item.clone()).collect()
|
self.iter().map(|item| item.clone()).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A: DeepClone> DeepClone for ~[A] {
|
||||||
|
#[inline]
|
||||||
|
fn deep_clone(&self) -> ~[A] {
|
||||||
|
self.iter().map(|item| item.deep_clone()).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This works because every lifetime is a sub-lifetime of 'static
|
// This works because every lifetime is a sub-lifetime of 'static
|
||||||
impl<'self, A> Zero for &'self [A] {
|
impl<'self, A> Zero for &'self [A] {
|
||||||
fn zero() -> &'self [A] { &'self [] }
|
fn zero() -> &'self [A] { &'self [] }
|
||||||
|
Loading…
Reference in New Issue
Block a user