List

Struct List 

Source
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>

Source

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())
Source

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'));
Source

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§

Source§

impl<T: Debug + Clone> Debug for List<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.