// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
using System.Diagnostics.Contracts;
namespace Geekeey.Request.Result;
public partial class Result
{
///
/// Implicitly constructs a result from a failure value.
///
/// The error to construct the result from.
[Pure]
public static implicit operator Result(Error error)
{
return new Result(error);
}
}
public partial class Result
{
///
/// Implicitly constructs a result from a success value.
///
/// The value to construct the result from.
[Pure]
public static implicit operator Result(T value)
{
return new Result(value);
}
///
/// Implicitly constructs a result from a failure value.
///
/// The error to construct the result from.
[Pure]
public static implicit operator Result(Error error)
{
return new Result(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()
{
return IsSuccess ? Value : throw new UnwrapException();
}
///
[Pure]
public static explicit operator T(Result result)
{
return result.Unwrap();
}
}