Skip to content

List

Module: std.collections.list
Source: std/collections/list.zn

Usage Example

use std.collections.list;
fn main() {
let items = List#[i32].new();
items.push(1);
items.push(2);
@println("len: {}", items.len());
}

List[T]

Dynamic heap-allocated array buffer


Fields:

ptr: [*]T,
_len: usize,
_capacity: usize,

Constructors:

pub fn new() Self;
pub fn with_capacity(capacity: usize) Self;
pub fn from[T: Copy](value: []const T) Self;
pub fn from_clone[T: Clone](value: []const T) Self;
pub fn from_raw_parts(ptr: [*]T, len: usize, capacity: usize) Self;

Getters:

pub fn len(*const self) usize;
pub fn capacity(*const self) usize;
pub fn is_empty(*const self) bool;
pub fn get[T: Copy](*const self, index: usize) Option[T];
pub fn get_ptr(*const self, index: usize) Option[*T];
pub fn first[T: Copy](*const self) Option[T];
pub fn last[T: Copy](*const self) Option[T];
pub fn find[T: Eq](*const self, value: *const T) Option[usize];
pub fn binary_search[T: Ord](*const self, value: *const T) Option[usize];

Mutations:

pub fn push(*self, value: T);
pub fn pop(*self) Option[T];
pub fn remove(*self, index: usize) Option[T];
pub fn set(*self, index: usize, value: T) Option[T];
pub fn insert(*self, index: usize, value: T);
pub fn append(*self, other: List[T]);
pub fn swap_remove(*self, index: usize) Option[T];
pub fn reverse(*self);
pub fn clear(*self);
pub fn truncate(*self, new_len: usize);
pub fn reserve(*self, additional: usize);

Sort:

pub fn sort[T: Ord](*self);
pub fn sort_by(*self, compare: fn(*const T, *const T) Ordering);

Interfaces:

  • core.ops : Drop, Clone (when T: Clone), Eq (when T: Eq), Index (when T: Copy), IndexPtr, Sliceable
  • core.iter : PtrIterator (when T: Copy), OwnedIterator (when T: Copy)
  • core.io : Debug (when T: Debug)

ListIter[T]

Borrowing iterator over List elements


Fields:

ptr: [*]T,
len: usize,
idx: usize,

Methods:

// No Methods

Interfaces:

  • core.iter : Iterator (when T: Copy)