using System.Diagnostics.Contracts; namespace Geekeey.Extensions.Result; public readonly partial struct Result { /// /// Implicitly constructs a result from a success value. /// /// The value to construct the result from. [Pure] public static implicit operator Result(T value) => new(value); /// /// Implicitly constructs a result from a failure value. /// /// The error to construct the result from. [Pure] public static implicit operator Result(Error error) => new(error); /// /// Unwraps the success value of the result. Throws an if the result is a failure. /// /// /// This call is unsafe in the sense that it might intentionally throw an exception. Please only use this /// call if the caller knows that this operation is safe, or that an exception is acceptable to be thrown. /// /// The success value of the result. /// The result is not a success. [Pure] public T Unwrap() => IsSuccess ? Value! : throw new UnwrapException(); /// [Pure] public static explicit operator T(Result result) => result.Unwrap(); }