Skip to content

Result struct

Namespace: Vitreous
Assembly: Vitreous.dll

Represents the outcome of a command that does not return a value. This is a discriminated union: either a success or an Error.

public readonly struct Result : IEquatable<Result>

IEquatable<Result>

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

A pre-allocated successful result.

public static readonly Result Success

Result

The failure error. For an uninitialized (default) result this is Uninitialized.

public Error Error { get; }

Error

InvalidOperationException

Thrown when the result is a success.

Returns true when the result represents a failure.

public bool IsFailure { get; }

bool

Returns true when the result represents a success.

public bool IsSuccess { get; }

bool

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Result other)

other Result

An object to compare with this object.

bool

true if the current object is equal to the other parameter; otherwise, false.

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

obj object?

The object to compare with the current instance.

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Creates a failed result wrapping error.

public static Result Fail(Error error)

error Error

Result

ArgumentNullException

Thrown when error is null.

Returns the hash code for this instance.

public override int GetHashCode()

int

A 32-bit signed integer that is the hash code for this instance.

Match<TOut>(Func<TOut>, Func<Error, TOut>)

Section titled “ Match<TOut>(Func<TOut>, Func<Error, TOut>)”

Executes onSuccess if successful, otherwise executes onFailure.

public TOut Match<TOut>(Func<TOut> onSuccess, Func<Error, TOut> onFailure)

onSuccess Func<TOut>

onFailure Func<Error, TOut>

TOut

TOut

MatchAsync<TOut>(Func<ValueTask<TOut>>, Func<Error, ValueTask<TOut>>)

Section titled “ MatchAsync<TOut>(Func<ValueTask<TOut>>, Func<Error, ValueTask<TOut>>)”

Async variant of Match<TOut>.

public ValueTask<TOut> MatchAsync<TOut>(Func<ValueTask<TOut>> onSuccess, Func<Error, ValueTask<TOut>> onFailure)

onSuccess Func<ValueTask<TOut>>

onFailure Func<Error, ValueTask<TOut>>

ValueTask<TOut>

TOut

Converts a non-generic Result into Result<T>, mapping success to successValue.

public Result<T> ToResult<T>(T successValue)

successValue T

Result<T>

T

Returns the fully qualified type name of this instance.

public override string ToString()

string

The fully qualified type name.

Returns true when both results are equal.

public static bool operator ==(Result left, Result right)

left Result

right Result

bool

Implicitly wraps an error as a failed result.

public static implicit operator Result(Error error)

error Error

Result

Returns true when the results differ.

public static bool operator !=(Result left, Result right)

left Result

right Result

bool