pub struct List<T: Clone> { /* private fields */ }
Expand description
List
struct is the singly linked generic data type
Implementations§
Source§impl<T: Clone> List<T>
impl<T: Clone> List<T>
Sourcepub fn new() -> List<T>
pub fn new() -> List<T>
Creates a new singly linked list
§Example:
use singly_linked_list::List;
let mut list: List<u32> = List::new();
assert_eq!(list.traverse(), Vec::new())
Sourcepub fn add_item(&mut self, value: T)
pub fn add_item(&mut self, value: T)
Adds a new item to the list
§Example
use singly_linked_list::List;
let mut list: List<char> = List::new();
list.add_item('a');
assert_eq!(list.traverse(), vec!('a'));
Sourcepub fn traverse(&self) -> Vec<T>
pub fn traverse(&self) -> Vec<T>
Traverse the hole list and returns a vector containing the list’s values
§Example
use singly_linked_list::List;
let mut list: List<f32> = List::new();
list.add_item(2.3);
list.add_item(4.3);
list.add_item(8.0);
list.add_item(5.6);
let list_values = list.traverse();
assert_eq!(list_values, vec!(2.3, 4.3, 8.0, 5.6));
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for List<T>where
T: Freeze,
impl<T> !RefUnwindSafe for List<T>
impl<T> !Send for List<T>
impl<T> !Sync for List<T>
impl<T> Unpin for List<T>where
T: Unpin,
impl<T> !UnwindSafe for List<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more