Ferrous API Reference

All Types / Ferrous.Results

class ErrorContextExtensions

public static class ErrorContextExtensions

anyhow::Context-inspired extension methods for attaching contextual error messages to Result<T, TError> values with zero allocation on the Ok path.

Methods

public static Result<T, ContextError> WithContext<T, TError>(this Result<T, TError> result, string context)

Wraps an Err value in a ContextError carrying context. Allocates nothing when the result is Ok.

public static Result<T, ContextError> WithContext<T, TError>(this Result<T, TError> result, Func<string> contextFactory)

Lazily evaluates contextFactory only when result is Err, wrapping the error in a ContextError. Allocates nothing on the Ok path.

public static async Task<Result<T, ContextError>> WithContextAsync<T, TError>(
        this Task<Result<T, TError>> resultTask,
        string context)

Asynchronously attaches context if the awaited Result<T, TError> is Err.

public static async ValueTask<Result<T, ContextError>> WithContextAsync<T, TError>(
        this ValueTask<Result<T, TError>> resultTask,
        string context)

Asynchronously attaches context if the awaited ValueTask<TResult> is Err.