diff --git a/src/linked_list.rs b/src/linked_list.rs index 8a93027..914a58a 100644 --- a/src/linked_list.rs +++ b/src/linked_list.rs @@ -1,9 +1,64 @@ -pub struct LinkedList {} +use std::ptr::NonNull; + +#[derive(Debug)] +pub struct LinkedList { + start: Option>>, + end: Option>>, +} + +impl Clone for LinkedList +where + T: Clone, +{ + fn clone(&self) -> Self { + todo!() + } +} pub struct Node { value: T, - next: *const Node, - prev: *const Node, + next: Option>>, + prev: Option>>, } +impl LinkedList { + pub fn new() -> Self { + Self { + start: None, + end: None, + } + } +} +impl IntoIterator for LinkedList { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> Self::IntoIter { + todo!() + } +} + +pub struct IntoIter { + item: Option>>, +} + +impl IntoIter { + fn new(list: LinkedList) -> Self { + Self { item: list.start } + } +} + +impl Iterator for IntoIter { + type Item = T; + + fn next(&mut self) -> Option { + let next = self.item.take(); + let ptr = match next { + None => return None, + Some(mut ptr) => unsafe { ptr.as_mut() }, + }; + + todo!() + } +}