|
core-adapters 0.1.2
Third-party adapters for snicholls-core: nanobind helpers, nlohmann/json hooks, the snicholls_core Python package
|
Values that may be missing: std::optional both ways, and a returned snicholls::result as value-or-raise.
More...
#include <nanobind/nanobind.h>#include <nanobind/stl/optional.h>#include <snicholls/core/result.hpp>#include <snicholls/core_adapters/nanobind/errors.hpp>#include <exception>#include <type_traits>#include <utility>Go to the source code of this file.
Values that may be missing: std::optional both ways, and a returned snicholls::result as value-or-raise.
std::optional<T> is T | None in both directions (nanobind's caster, included here so one include covers the family's two "maybe" types). Core uses std::optional where absence is not an error: a parse that may fail, uint256 arithmetic, uuid text.snicholls::result<V, E> as a return type is V (None for result<void, E>): an error result raises, through snicholls::python::raise_error (errors.hpp) - a traced error as TracedError with its location, anything else as ResultError or as the standard exception it already is. A binding can therefore return core's results directly, with no unwrap in sight. A result is never accepted as an argument.errors.hpp (raise_error, set_python_error, register_exception_translators); <nanobind/stl/optional.h>.result caster converts the value with V's own caster and return-value policy; it never throws (it sets the Python error and returns a null handle, as nanobind requires).errors.hpp: the Python class follows the error type.V's own conversion on success.scripts/demos/optional_demo.sh.snicholls::core_nanobind; core's result.hpp.result<V, E> function as returning V; document what it raises in the docstring.Definition in file optional.hpp.