fixes and adjustments
.NET Test / .NET tests (push) Successful in 2m53s

This commit is contained in:
2026-07-16 19:00:05 +04:00
parent 0e7986996f
commit 04c682d6fd
4 changed files with 177 additions and 28 deletions
+24 -11
View File
@@ -45,6 +45,9 @@ public readonly partial struct Result : IEquatable<Result>
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result Failure(string error) => Error.New(error ?? throw new ArgumentNullException(nameof(error)));
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result Failure(string type, string error) => Error.New(type, error ?? throw new ArgumentNullException(nameof(error)));
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result Failure(Error error) => new(error ?? throw new ArgumentNullException(nameof(error)));
@@ -54,6 +57,9 @@ public readonly partial struct Result : IEquatable<Result>
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result<T> Failure<T>(string error) => Error.New(error ?? throw new ArgumentNullException(nameof(error)));
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result<T> Failure<T>(string type, string error) => Error.New(type, error ?? throw new ArgumentNullException(nameof(error)));
[Pure, MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result<T> Failure<T>(Error error) => new(error ?? throw new ArgumentNullException(nameof(error)));
@@ -76,7 +82,10 @@ public readonly partial struct Result : IEquatable<Result>
public static explicit operator Result(SuccessUnit _) => new(null);
[Pure] public bool IsSuccess => State == ResultState.Success;
[Pure] public bool IsFailure => State == ResultState.Error;
[Pure]
[MemberNotNullWhen(true, nameof(Error))]
public bool IsFailure => State == ResultState.Error;
[Pure] public bool TryGetValue([MaybeNullWhen(false)]out SuccessUnit? u, [MaybeNullWhen(true), NotNullWhen(false)]out Error? error)
{
@@ -97,17 +106,18 @@ public readonly partial struct Result : IEquatable<Result>
}
[Pure] public bool TryGetError([MaybeNullWhen(false)]out Error error)
{
if (IsSuccess)
switch (State)
{
error = default;
return false;
case ResultState.Success:
error = default;
return false;
case ResultState.Error:
error = Error!;
return true;
default: throw new ResultNotInitializedException();
}
if (IsFailure)
{
error = Error!;
return true;
}
throw new ResultNotInitializedException();
}
[Pure] public override string ToString() => State switch
@@ -127,9 +137,12 @@ public readonly partial struct Result : IEquatable<Result>
[Pure] public override bool Equals(object? obj) => obj is Result other && Equals(other);
[Pure] public bool Equals(Result other)
{
if (State == ResultState.Bottom || other.State == ResultState.Bottom)
if (State == ResultState.Bottom)
throw new ResultNotInitializedException();
if (other.State == ResultState.Bottom)
throw new ResultNotInitializedException(nameof(other));
return Error == other.Error;
}
[Pure] public static bool operator ==(Result left, Result right) => left.Equals(right);