Implement Clone and Default for bforest::{Set,Map}.
The default container is empty. We need a manual implementation of Default because deriving it seems to imply that K and V generic parameter types must also implement Default. Cloning can be used to clone an empty container or for cloning the whole forest. We can derive this trait because we already require Copy for K and V.
This commit is contained in:
@@ -61,6 +61,11 @@ where
|
||||
///
|
||||
/// This is not a general-purpose replacement for `BTreeMap`. See the [module
|
||||
/// documentation](index.html) for more information about design tradeoffs.
|
||||
///
|
||||
/// Maps can be cloned, but that operation should only be used as part of cloning the whole forest
|
||||
/// they belong to. *Cloning a map does not allocate new memory for the clone*. It creates an alias
|
||||
/// of the same memory.
|
||||
#[derive(Clone)]
|
||||
pub struct Map<K, V, C>
|
||||
where
|
||||
K: Copy,
|
||||
@@ -145,6 +150,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, C> Default for Map<K, V, C>
|
||||
where
|
||||
K: Copy,
|
||||
V: Copy,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<K, V, C> Map<K, V, C>
|
||||
where
|
||||
|
||||
@@ -58,6 +58,11 @@ where
|
||||
///
|
||||
/// This is not a general-purpose replacement for `BTreeSet`. See the [module
|
||||
/// documentation](index.html) for more information about design tradeoffs.
|
||||
///
|
||||
/// Sets can be cloned, but that operation should only be used as part of cloning the whole forest
|
||||
/// they belong to. *Cloning a set does not allocate new memory for the clone*. It creates an alias
|
||||
/// of the same memory.
|
||||
#[derive(Clone)]
|
||||
pub struct Set<K, C>
|
||||
where
|
||||
K: Copy,
|
||||
@@ -142,6 +147,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, C> Default for Set<K, C>
|
||||
where
|
||||
K: Copy,
|
||||
C: Comparator<K>,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// A position in a `Set` used to navigate and modify the ordered set.
|
||||
///
|
||||
/// A cursor always points at an element in the set, or "off the end" which is a position after the
|
||||
|
||||
Reference in New Issue
Block a user