Result
io.github.ykysnk.utils.NonUdon · public readonly struct Result<T>
Outcome of an operation that can fail: either a value or the exception that stopped it.
The success flag is explicit rather than inferred from the value, so Result<int> can carry a genuine 0 and still report success. The constructors are private; build results with Success, Failure or Try.Run.
Value
public T? Value { get; }Whatever the delegate returned. On failure this is the default of T; a null value on a successful result is allowed and is not an error.
Exception
public Exception? Exception { get; }The captured exception with its original stack trace, or null on success.
IsSuccess
public bool IsSuccess { get; }Whether the call completed without throwing, i.e. whether Exception is null.
Success
public static Result<T> Success(T value)Builds a successful result with Exception cleared. A null value is allowed and still counts as success.
Failure
public static Result<T> Failure(Exception exception)Builds a failed result carrying exception as-is, not unwrapped or rethrown, with Value set to the default of T.
Deconstruct
public void Deconstruct(out bool isSuccess, out T? value, out Exception? exception)Splits the result into its three readable parts, which is what a deconstruction assignment calls.
var (success, value, error) = Try.Run(() => int.Parse(text));operator true
public static bool operator true(Result<T> r)Reports success, so a result can be used directly in a conditional.
if (result)
Use(result.Value);operator false
public static bool operator false(Result<T> r)Reports failure. The compiler requires it alongside the true operator for conditional use.
ToString
public override string ToString()Renders the outcome as Success(value) or Failure(exception), using the exception's own ToString().