From 5a5b600490f9c2ecf0f3ee03b376fa1660663f3f Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Tue, 10 Oct 2023 21:20:55 +0200 Subject: [PATCH] std::collections::list: add List.init_from_array Signed-off-by: Pierre Curto --- lib/std/collections/list.c3 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index 3aa1325f6..fbfe96b90 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -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)