Skip to main content

Result

Result type representing either success (Ok) or failure (Err) Example usage:

Public Methods


Result

Deleted constructor.

Result

inline

Result

inline

is_ok

const
Check if result is successful.

is_err

const
Check if result is an error.

unwrap

const
Get the value (throws if error) Use is_ok() to check first, or use unwrap_or()

unwrap

inline

unwrap_or

const
Get the value or a default.

unwrap_or_else

const
Get the value or compute from error.

error

const
Get error message.

code

const
Get error code.

map

const
Map the value if Ok, preserve error if Err.

operator bool

const explicit
Convert to bool (true if Ok)

Public Static Methods


Ok

static
Create a successful result.

Ok

static

Err

static
Create an error result.

Parameters

  • code Error code (use HTTP-style: 400=bad request, 404=not found, 500=internal error)
  • msg Human-readable error message

Private Attributes


value_


is_ok_


error_msg_


error_code_

Private Methods


Result

inline

Result

inline