Some checks failed
default / dotnet-default-workflow (push) Failing after 1m24s
Add a simple in memory dispatcher for scalar requests and stream request.
51 lines
No EOL
1.4 KiB
C#
51 lines
No EOL
1.4 KiB
C#
// Copyright (c) The Geekeey Authors
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
using System.Diagnostics.Contracts;
|
|
|
|
namespace Geekeey.Request.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)
|
|
{
|
|
return new Result<T>(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)
|
|
{
|
|
return new Result<T>(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()
|
|
{
|
|
return IsSuccess ? Value : throw new UnwrapException();
|
|
}
|
|
|
|
/// <inheritdoc cref="Unwrap"/>
|
|
[Pure]
|
|
public static explicit operator T(Result<T> result)
|
|
{
|
|
return result.Unwrap();
|
|
}
|
|
} |