feat: initial project commit
Some checks failed
dotnet publish / package (8.0) (push) Failing after 8s

This commit is contained in:
Louis Seubert 2024-04-14 17:42:13 +02:00
commit 87a93fa2df
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
39 changed files with 3658 additions and 0 deletions

View file

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