Skip to content

Commit

Permalink
std::collections::list: add List.init_from_array
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Curto <[email protected]>
  • Loading branch information
pierrec authored and lerno committed Oct 11, 2023
1 parent 1472d60 commit 5a5b600
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/std/collections/list.c3
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ fn void List.tinit(&self, usz initial_capacity = 16)
self.init(initial_capacity, mem::temp()) @inline;
}

/**
* Initialize the List by referencing the provided types.
* @require self.size == 0 "The List must be empty"
**/
fn void List.init_wrapping_array(&self, Type[] types, Allocator* using = mem::heap())
{
self.allocator = using;
self.size = types.len;
self.capacity = types.len;
self.entries = types.ptr;
}

fn usz! List.to_format(&self, Formatter* formatter) @dynamic
{
switch (self.size)
Expand Down

0 comments on commit 5a5b600

Please sign in to comment.