using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; namespace Geekeey.Common.Results; public readonly partial struct Result { /// /// Tries to get the success value from the result. /// /// The success value of the result. /// Whether the result has success value. [Pure] public bool TryGetValue([MaybeNullWhen(false)] out T value) { value = Value!; return _success; } /// /// Tries to get the success value from the result. /// /// The success value of the result. /// The failure value of the result. /// Whether the result has a success value. [Pure] public bool TryGetValue([MaybeNullWhen(false)] out T value, [MaybeNullWhen(true)] out Error error) { value = Value!; error = !_success ? Error : null!; return _success; } /// /// Tries to get the failure value from the result. /// /// The failure value of the result. /// Whether the result has a failure value. [Pure] public bool TryGetError([MaybeNullWhen(false)] out Error error) { error = !_success ? Error : null!; return !_success; } /// /// Tries to get the failure value from the result. /// /// The failure value of the result. /// The success value of the result. /// Whether the result a failure value. [Pure] public bool TryGetError([MaybeNullWhen(false)] out Error error, [MaybeNullWhen(true)] out T value) { error = !_success ? Error : null!; value = Value!; return !_success; } }