mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-01 07:09:35 +02:00
Remove Copy bound from binary tree exercise (#1606)
There's absolutely no need for the element type of the binary tree to be `Copy`. Let's remove this bound hence.
This commit is contained in:
parent
52bfb0c4a3
commit
8e4bb60023
@ -18,7 +18,7 @@ use std::cmp::Ordering;
|
|||||||
// ANCHOR: types
|
// ANCHOR: types
|
||||||
/// A node in the binary tree.
|
/// A node in the binary tree.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Node<T: Ord + Copy> {
|
struct Node<T: Ord> {
|
||||||
value: T,
|
value: T,
|
||||||
left: Subtree<T>,
|
left: Subtree<T>,
|
||||||
right: Subtree<T>,
|
right: Subtree<T>,
|
||||||
@ -26,18 +26,18 @@ struct Node<T: Ord + Copy> {
|
|||||||
|
|
||||||
/// A possibly-empty subtree.
|
/// A possibly-empty subtree.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Subtree<T: Ord + Copy>(Option<Box<Node<T>>>);
|
struct Subtree<T: Ord>(Option<Box<Node<T>>>);
|
||||||
|
|
||||||
/// A container storing a set of values, using a binary tree.
|
/// A container storing a set of values, using a binary tree.
|
||||||
///
|
///
|
||||||
/// If the same value is added multiple times, it is only stored once.
|
/// If the same value is added multiple times, it is only stored once.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BinaryTree<T: Ord + Copy> {
|
pub struct BinaryTree<T: Ord> {
|
||||||
root: Subtree<T>,
|
root: Subtree<T>,
|
||||||
}
|
}
|
||||||
// ANCHOR_END: types
|
// ANCHOR_END: types
|
||||||
|
|
||||||
impl<T: Ord + Copy> BinaryTree<T> {
|
impl<T: Ord> BinaryTree<T> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
root: Subtree::new(),
|
root: Subtree::new(),
|
||||||
@ -57,7 +57,7 @@ impl<T: Ord + Copy> BinaryTree<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord + Copy> Subtree<T> {
|
impl<T: Ord> Subtree<T> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self(None)
|
Self(None)
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ impl<T: Ord + Copy> Subtree<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord + Copy> Node<T> {
|
impl<T: Ord> Node<T> {
|
||||||
fn new(value: T) -> Self {
|
fn new(value: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
value,
|
value,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user