@ts-rust/std - v0.0.5
    Preparing search index...

    Function err

    • Creates an Err variant of a Result with a void error.

      Wraps undefined in a CheckedError within an Err, indicating a failed outcome with no error value for a checked Result.

      Type Parameters

      • T

        The type of the potential value.

      Parameters

      • error: void

        The void error (typically omitted or undefined).

      Returns Result<T, void>

      A Result containing undefined as Err.

      const x = err<number>();

      expect(x.isErr()).toBe(true);
      expect(x.unwrapErr().expected).toBeUndefined();
      expect(x.unwrapErr().unexpected).toBeUndefined();
    • Creates an Err variant of a Result containing the given error.

      Wraps the provided error in a CheckedError within an Err, indicating a failed outcome for a checked Result. This function accepts raw errors, ResultError, or CheckedError.

      • If called with an error of type E, it creates an ExpectedError variant.
      • If called with a CheckedError, it uses the error as is.

      Type Parameters

      • T

        The type of the potential value.

      • E

        The type of the expected error.

      Parameters

      Returns Result<T, E>

      A Result containing the error as Err.

      const oops = new ResultError("err", ResultErrorKind.Unexpected);
      const x = err<number, string>("failure");
      const y = err<number, string>(oops);

      expect(x.isErr()).toBe(true);
      expect(x.unwrapErr().expected).toBe("failure");
      expect(y.unwrapErr().unexpected).toBe(oops);