Template Class Result

Template Parameter Order

  1. typename T

  2. typename E

Class Documentation

template<typename T, typename E>
class Result

Represents either a value or an error.

Template Parameters:
  • T – The type of the value.

  • E – The type of the error.

Public Functions

inline constexpr Result(Ok<T> value)
inline constexpr Result(Err<E> value)
inline constexpr bool is_ok()
inline constexpr bool is_err()
inline constexpr T unwrap(const FormatWithLocation &fmt = "unwrap failed: cannot unwrap an error type, err: {}")

Gets the Ok value if present and panics if called on an Err value.

Parameters:

fmt – Panic message when called on an Err value (optional)

Returns:

The Ok value contained

inline constexpr T unwrap_or(T _value)

Gets the Ok value if present or returns a default value.

Parameters:

_value – The value returned on error

Returns:

The Ok value or _value

inline constexpr frg::optional<E> error()

Gets the Err value.

Returns:

the Err value if present or frg::null_opt otherwise

inline constexpr frg::optional<T> value()

Gets the Ok value.

Returns:

the Ok value if present or frg::null_opt otherwise