feat: initial project commit
All checks were successful
default / default (8.0) (push) Successful in 1m7s
All checks were successful
default / default (8.0) (push) Successful in 1m7s
This commit is contained in:
commit
30ef7bd477
40 changed files with 3752 additions and 0 deletions
36
src/Result/Result.Conversion.cs
Normal file
36
src/Result/Result.Conversion.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Geekeey.Extensions.Result;
|
||||
|
||||
public readonly partial struct Result<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Implicitly constructs a result from a success value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to construct the result from.</param>
|
||||
[Pure]
|
||||
public static implicit operator Result<T>(T value) => new(value);
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly constructs a result from a failure value.
|
||||
/// </summary>
|
||||
/// <param name="error">The error to construct the result from.</param>
|
||||
[Pure]
|
||||
public static implicit operator Result<T>(Error error) => new(error);
|
||||
|
||||
/// <summary>
|
||||
/// Unwraps the success value of the result. Throws an <see cref="UnwrapException"/> if the result is a failure.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This call is <b>unsafe</b> 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.
|
||||
/// </remarks>
|
||||
/// <returns>The success value of the result.</returns>
|
||||
/// <exception cref="UnwrapException">The result is not a success.</exception>
|
||||
[Pure]
|
||||
public T Unwrap() => IsSuccess ? Value! : throw new UnwrapException();
|
||||
|
||||
/// <inheritdoc cref="Unwrap"/>
|
||||
[Pure]
|
||||
public static explicit operator T(Result<T> result) => result.Unwrap();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue