From fe68fce478199e6140de4bba43c8ac8994821cbe Mon Sep 17 00:00:00 2001 From: Viktor Stojanovic Date: Wed, 12 Aug 2026 18:36:26 +0200 Subject: [PATCH 1/2] Make Result readonly. Add true & false operators. Add constructors --- src/Result.cs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Result.cs b/src/Result.cs index 625f973..39045e1 100644 --- a/src/Result.cs +++ b/src/Result.cs @@ -5,11 +5,33 @@ namespace UnmanagedResult; -public struct Result : IResult> +public readonly struct Result : IResult> where TValue : unmanaged where TEnum : unmanaged, Enum { - public TValue Value => throw new System.NotImplementedException(); + private readonly byte _flags; + private readonly TValue _value; + private readonly Error _error; - public Error Error => default; + public Result(TValue value) + { + _value = value; + _flags = 0; + } + + public Result(Error error) + { + _error = error; + _flags = 1; + } + + public static bool operator true(Result result) + { + return result._flags is 0; + } + + public static bool operator false(Result result) + { + return result._flags is not 0; + } } \ No newline at end of file From bdda82852ba84cb27bcc786628cd0889749eddc6 Mon Sep 17 00:00:00 2001 From: Viktor Stojanovic Date: Wed, 12 Aug 2026 18:38:58 +0200 Subject: [PATCH 2/2] Fix formating --- src/Result.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Result.cs b/src/Result.cs index 39045e1..c80c76d 100644 --- a/src/Result.cs +++ b/src/Result.cs @@ -7,10 +7,10 @@ namespace UnmanagedResult; public readonly struct Result : IResult> where TValue : unmanaged - where TEnum : unmanaged, Enum + where TEnum : unmanaged, Enum { - private readonly byte _flags; - private readonly TValue _value; + private readonly byte _flags; + private readonly TValue _value; private readonly Error _error; public Result(TValue value)