pub struct Node<T> {
    pub next: Option<NonNull<Node<T>>>,
    pub value: T,
}
Expand description

Node for representing values in a [SinglyLinkedList].

Fields

next: Option<NonNull<Node<T>>>

Next Node within the [SinglyLinkedList].

value: T

Value of the Node.

Implementations

Creates a new Node with the coresponding value and a Nonein the next field.

Example
let node = Node::new("New Node");
assert_eq!(node.next, None);
assert_eq!(node.value, "New Node");

Converts the Node into a Box-ed version of the Node.

Example
let boxed_node = Node::new(5).into_box();
assert_eq!(boxed_node, Box::new(Node::new(5)));

Converts the Node into a Box, then converts the Box into a NonNull of the Node.

Example
let ptr = Node::new(5).into_non_null();
let value = unsafe { &ptr.as_ref().value };
 
assert_eq!(value, &5);
Safety
  • Converts the Node into a Box before NonNull conversion, ptr should always be valid.

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.