pub trait List<Item> {
// Required methods
fn first(&self) -> Option<&Item>;
fn last(&self) -> Option<&Item>;
fn repeat(self, n: usize) -> Self
where Item: Clone;
}Expand description
List operations.
Methods have the following properties:
- Requires the collection to represent a list
- Does not consume the list or its elements
- Does not create a new list
Required Methods§
sourcefn first(&self) -> Option<&Item>
fn first(&self) -> Option<&Item>
Returns the first element of this sequence, or None if it is empty.
§Examples
use cantrip::*;
use std::collections::LinkedList;
let a = LinkedList::from([1, 2, 3]);
assert_eq!(a.first(), Some(&1));sourcefn last(&self) -> Option<&Item>
fn last(&self) -> Option<&Item>
Returns the last element of this sequence, or None if it is empty.
§Examples
use cantrip::*;
use std::collections::LinkedList;
let a = LinkedList::from([1, 2, 3]);
assert_eq!(a.last(), Some(&3));sourcefn repeat(self, n: usize) -> Selfwhere
Item: Clone,
fn repeat(self, n: usize) -> Selfwhere
Item: Clone,
Creates a new collection by repeating this collection specified number of times.
§Example
use cantrip::*;
use std::collections::LinkedList;
let a = LinkedList::from([1, 2, 3]);
assert_eq!(a.repeat(2), LinkedList::from([1, 2, 3, 1, 2, 3]));
assert_eq!(a.repeat(0), LinkedList::new());Object Safety§
This trait is not object safe.