From 1c520dce4583a9bdc8ce06ca4f5e500cccc4fea5 Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Fri, 6 Aug 2021 20:26:49 +0200 Subject: [PATCH] iter --- src/linked_list.rs | 61 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) 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!() + } +}