I think I solved the clone issue by manually implementing clone since the Rc needs to be cloned, not the content inside it.
This commit is contained in:
parent
2db400198e
commit
fb8a31a88f
@ -1,10 +1,18 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug)]
|
||||||
pub struct List<T> {
|
pub struct List<T> {
|
||||||
head: Option<Rc<Node<T>>>,
|
head: Option<Rc<Node<T>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Clone for List<T> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
List {
|
||||||
|
head: self.head.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Node<T> {
|
pub struct Node<T> {
|
||||||
data: T,
|
data: T,
|
||||||
@ -27,7 +35,7 @@ impl<T> List<T> {
|
|||||||
|
|
||||||
pub fn without_front(&self) -> List<T> {
|
pub fn without_front(&self) -> List<T> {
|
||||||
List {
|
List {
|
||||||
head: self.head.as_ref().map(|node| node.parent.clone()).flatten()
|
head: self.head.as_ref().map(|node| node.parent.clone()).flatten(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user