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:
Tom Alexander 2022-12-04 00:02:15 -05:00
parent 2db400198e
commit fb8a31a88f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 10 additions and 2 deletions

View File

@ -1,10 +1,18 @@
use std::rc::Rc;
#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct List<T> {
head: Option<Rc<Node<T>>>,
}
impl<T> Clone for List<T> {
fn clone(&self) -> Self {
List {
head: self.head.clone(),
}
}
}
#[derive(Debug, Clone)]
pub struct Node<T> {
data: T,
@ -27,7 +35,7 @@ impl<T> List<T> {
pub fn without_front(&self) -> List<T> {
List {
head: self.head.as_ref().map(|node| node.parent.clone()).flatten()
head: self.head.as_ref().map(|node| node.parent.clone()).flatten(),
}
}