Skip to content

Commit 2d3b165

Browse files
committed
impl {Default,Clone,From<&Slice>} for Box<Slice>
1 parent 8c49292 commit 2d3b165

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/map/slice.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,24 @@ impl<K, V> Default for &'_ mut Slice<K, V> {
258258
}
259259
}
260260

261+
impl<K, V> Default for Box<Slice<K, V>> {
262+
fn default() -> Self {
263+
Slice::from_boxed(Box::default())
264+
}
265+
}
266+
267+
impl<K: Clone, V: Clone> Clone for Box<Slice<K, V>> {
268+
fn clone(&self) -> Self {
269+
Slice::from_boxed(self.entries.to_vec().into_boxed_slice())
270+
}
271+
}
272+
273+
impl<K: Copy, V: Copy> From<&Slice<K, V>> for Box<Slice<K, V>> {
274+
fn from(slice: &Slice<K, V>) -> Self {
275+
Slice::from_boxed(slice.entries.to_vec().into_boxed_slice())
276+
}
277+
}
278+
261279
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Slice<K, V> {
262280
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
263281
f.debug_list().entries(self).finish()

src/set/slice.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ impl<T> Default for &'_ Slice<T> {
139139
}
140140
}
141141

142+
impl<T> Default for Box<Slice<T>> {
143+
fn default() -> Self {
144+
Slice::from_boxed(Box::default())
145+
}
146+
}
147+
148+
impl<T: Clone> Clone for Box<Slice<T>> {
149+
fn clone(&self) -> Self {
150+
Slice::from_boxed(self.entries.to_vec().into_boxed_slice())
151+
}
152+
}
153+
154+
impl<T: Copy> From<&Slice<T>> for Box<Slice<T>> {
155+
fn from(slice: &Slice<T>) -> Self {
156+
Slice::from_boxed(slice.entries.to_vec().into_boxed_slice())
157+
}
158+
}
159+
142160
impl<T: fmt::Debug> fmt::Debug for Slice<T> {
143161
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
144162
f.debug_list().entries(self).finish()

0 commit comments

Comments
 (0)