Skip to content

Commit a8f383a

Browse files
Merge pull request #696 from frankmcsherry/columnar_clone_from
Manually implement `Clone::clone_from`
2 parents 7f5b66e + 222a468 commit a8f383a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

timely/examples/columnar.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ mod container {
135135
// The clone implementation moves out of the `Bytes` variant into `Align`.
136136
// This is optional and non-optimal, as the bytes clone is relatively free.
137137
// But, we don't want to leak the uses of `Bytes`, is why we do this I think.
138-
impl<C: Clone> Clone for Column<C> where C: Clone {
138+
impl<C: columnar::Container> Clone for Column<C> where C: Clone {
139139
fn clone(&self) -> Self {
140140
match self {
141141
Column::Typed(t) => Column::Typed(t.clone()),
@@ -148,6 +148,18 @@ mod container {
148148
Column::Align(a) => Column::Align(a.clone()),
149149
}
150150
}
151+
fn clone_from(&mut self, other: &Self) {
152+
match (self, other) {
153+
(Column::Typed(t0), Column::Typed(t1)) => {
154+
// Derived `Clone` implementations for e.g. tuples cannot be relied on to call `clone_from`.
155+
let t1 = t1.borrow();
156+
t0.clear();
157+
t0.extend_from_self(t1, 0..t1.len());
158+
}
159+
(Column::Align(a0), Column::Align(a1)) => { a0.clone_from(a1); }
160+
(x, y) => { *x = y.clone(); }
161+
}
162+
}
151163
}
152164

153165
use columnar::{Len, Index, FromBytes};

0 commit comments

Comments
 (0)