jubilant-funicular
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
nta::Result< T > Class Template Reference

#include <Errors.h>

Collaboration diagram for nta::Result< T >:
Collaboration graph
[legend]

Public Member Functions

 Result (const Result &other)
 Public copy constructor.
 
 ~Result ()
 Public destructor.
 
bool is_err () const
 Is this an Error.
 
bool is_ok () const
 Is this normal data.
 
get_data () const
 Get the data (only use if is_ok() returns true)
 
unwrap () const
 Same as get_data.
 
Error get_err () const
 Get the Error (only use if is_err() returns true)
 
get_data_or (T optb) const
 Tries getting data, returning a default value if this is an error.
 
unwrap_or (T optb) const
 Same as get_data_or.
 
template<typename S >
Result< S > map (std::function< S(T)> func)
 Applies a function if no error has occured, else returns the same error.
 
utils::Option< Errormap (std::function< void(T)> func)
 
template<typename S >
Result< S > convert_error ()
 Converts an error variant of Result<T> to an error variant of Result
 

Static Public Member Functions

static Result new_ok (const T &data)
 
static Result new_err (const Error &err)
 

Private Member Functions

 Result ()
 Private constructor (use new_ok or new_err)
 

Private Attributes

union {
data
 
Error err
 
}; 
 The data or error held by this Result.
 
bool is_err_variant
 Whether or not an error occured.
 

Detailed Description

template<typename T>
class nta::Result< T >

Used for returning data when an error could potentially occur

Todo:
Use Result type everywhere it needs to be used

Definition at line 74 of file Errors.h.

Member Function Documentation

◆ new_err()

template<typename T >
static Result nta::Result< T >::new_err ( const Error err)
inlinestatic

Create new Result holding an Error

This takes ownership of the err passed in

Definition at line 110 of file Errors.h.

Referenced by nta::Result< T >::convert_error(), nta::ContextData::getTextureFile(), and nta::Result< T >::map().

◆ new_ok()

template<typename T >
static Result nta::Result< T >::new_ok ( const T &  data)
inlinestatic

Create new Result holding normal data

This takes ownership of the data passed in

Definition at line 101 of file Errors.h.

Referenced by nta::ContextData::getSpriteFont(), nta::ResourceManager::getTexture(), nta::ContextData::getTexture(), nta::ContextData::getTextureFile(), and nta::Result< T >::map().


The documentation for this class was generated from the following file: