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>Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Fields
Section titled “Fields”Success
Section titled “ Success”A pre-allocated successful result.
public static readonly Result SuccessField Value
Section titled “Field Value”Properties
Section titled “Properties”The failure error. For an uninitialized (default) result this is Uninitialized.
public Error Error { get; }Property Value
Section titled “Property Value”Exceptions
Section titled “Exceptions”Thrown when the result is a success.
IsFailure
Section titled “ IsFailure”Returns true when the result represents a failure.
public bool IsFailure { get; }Property Value
Section titled “Property Value”IsSuccess
Section titled “ IsSuccess”Returns true when the result represents a success.
public bool IsSuccess { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”Equals(Result)
Section titled “ Equals(Result)”Indicates whether the current object is equal to another object of the same type.
public bool Equals(Result other)Parameters
Section titled “Parameters”other Result
An object to compare with this object.
Returns
Section titled “Returns”true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
Section titled “ Equals(object?)”Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)Parameters
Section titled “Parameters”obj object?
The object to compare with the current instance.
Returns
Section titled “Returns”true if obj and this instance are the same type and represent the same value; otherwise, false.
Fail(Error)
Section titled “ Fail(Error)”Creates a failed result wrapping error.
public static Result Fail(Error error)Parameters
Section titled “Parameters”error Error
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”Thrown when error is null.
GetHashCode()
Section titled “ GetHashCode()”Returns the hash code for this instance.
public override int GetHashCode()Returns
Section titled “Returns”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)Parameters
Section titled “Parameters”onSuccess Func<TOut>
Returns
Section titled “Returns”TOut
Type Parameters
Section titled “Type Parameters”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)Parameters
Section titled “Parameters”onSuccess Func<ValueTask<TOut>>
onFailure Func<Error, ValueTask<TOut>>
Returns
Section titled “Returns”ValueTask<TOut>
Type Parameters
Section titled “Type Parameters”TOut
ToResult<T>(T)
Section titled “ ToResult<T>(T)”Converts a non-generic Result into Result<T>,
mapping success to successValue.
public Result<T> ToResult<T>(T successValue)Parameters
Section titled “Parameters”successValue T
Returns
Section titled “Returns”Result<T>
Type Parameters
Section titled “Type Parameters”T
ToString()
Section titled “ ToString()”Returns the fully qualified type name of this instance.
public override string ToString()Returns
Section titled “Returns”The fully qualified type name.
Operators
Section titled “Operators”operator ==(Result, Result)
Section titled “ operator ==(Result, Result)”Returns true when both results are equal.
public static bool operator ==(Result left, Result right)Parameters
Section titled “Parameters”left Result
right Result
Returns
Section titled “Returns”implicit operator Result(Error)
Section titled “ implicit operator Result(Error)”Implicitly wraps an error as a failed result.
public static implicit operator Result(Error error)Parameters
Section titled “Parameters”error Error
Returns
Section titled “Returns”operator !=(Result, Result)
Section titled “ operator !=(Result, Result)”Returns true when the results differ.
public static bool operator !=(Result left, Result right)Parameters
Section titled “Parameters”left Result
right Result