Improved error message when accessing @private from other modules. Added convenience functions to Maybe.

This commit is contained in:
Christoffer Lerno
2025-01-04 14:58:06 +01:00
parent 469188044d
commit e31e57c7e7
6 changed files with 51 additions and 11 deletions

View File

@@ -1,16 +1,43 @@
module std::collections::maybe(<Type>);
import std::io;
struct Maybe
struct Maybe (Printable)
{
Type value;
bool has_value;
}
fn usz! Maybe.to_format(&self, Formatter* f) @dynamic
{
if (self.has_value) return f.printf("[%s]", self.value);
return f.printf("[EMPTY]");
}
fn void Maybe.set(&self, Type val)
{
*self = { .value = val, .has_value = true };
}
fn void Maybe.reset(&self)
{
*self = {};
}
fn Maybe value(Type val)
{
return { .value = val, .has_value = true };
}
fn Maybe Maybe.with_value(Type val) @operator(construct)
{
return { .value = val, .has_value = true };
}
fn Maybe Maybe.empty() @operator(construct)
{
return { };
}
const Maybe EMPTY = { };
macro Type! Maybe.get(self)