From 9807cd21b17ff37d0a70ccaeb9c72f29d932ea3f Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Thu, 14 May 2026 14:50:01 +0200 Subject: [PATCH] std/option instead of inside collections --- std/collections.jam | 15 +++++---------- std/option.jam | 11 +++++++++++ tests/unit/test_vec.jam | 5 +++-- 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 std/option.jam diff --git a/std/collections.jam b/std/collections.jam index 889be92..d520354 100644 --- a/std/collections.jam +++ b/std/collections.jam @@ -1,26 +1,21 @@ // std.collections — dynamic data structures. // -// `Option(T)` — tagged optional. `Some(T)` carries a value; `None` -// signals absence. Used by fallible getters / poppers. -// // `Vec(T)` — growable dynamic array. Uses libc malloc / free / // realloc as the backing allocator. MVS auto-drops the backing // buffer at scope exit. A user-pluggable Allocator interface is // deferred until function-pointer support lands in the compiler; // once it does, `std.mem.Allocator` will be a runtime vtable type // matching Zig's `std.mem.Allocator`. +// +// `Option(T)` lives in `std/option` and is imported here for +// fallible getters / poppers. + +const { Option } = import("option"); pub extern fn malloc(size: u64) *mut[] u8; pub extern fn free(ptr: *mut[] u8); pub extern fn realloc(ptr: *mut[] u8, size: u64) *mut[] u8; -pub fn Option(T: type) type { - return enum { - Some(T), - None, - }; -} - pub fn Vec(T: type) type { return struct { ptr: *mut[] T, diff --git a/std/option.jam b/std/option.jam new file mode 100644 index 0000000..83abf8b --- /dev/null +++ b/std/option.jam @@ -0,0 +1,11 @@ +// std.option — tagged optional value. +// +// `Option(T)` carries a value via `Some(T)` or signals absence via +// `None`. Match-exhaustive: every consumer must handle both arms. + +pub fn Option(T: type) type { + return enum { + Some(T), + None, + }; +} diff --git a/tests/unit/test_vec.jam b/tests/unit/test_vec.jam index 83af982..9d600de 100644 --- a/tests/unit/test_vec.jam +++ b/tests/unit/test_vec.jam @@ -1,6 +1,7 @@ -// `Vec(T)` and `Option(T)` consumed from std.collections. +// `Vec(T)` from std.collections; `Option(T)` from std.option. const { assert } = import("test"); -const { Vec, Option } = import("collections"); +const { Vec } = import("std/collections"); +const { Option } = import("std/option"); const VecI32 = Vec(i32); const VecU8 = Vec(u8); -- 2.51.2