50#ifndef snicholls_core_adapters_nanobind_optional_hpp
51#define snicholls_core_adapters_nanobind_optional_hpp
53#include <nanobind/nanobind.h>
54#include <nanobind/stl/optional.h>
56#include <snicholls/core/result.hpp>
63namespace nanobind::detail {
66template <
class V,
class E>
67struct type_caster<snicholls::result<V, E>>
69 using Value = snicholls::result<V, E>;
70 static constexpr auto Name = [] {
71 if constexpr (std::is_void_v<V>)
72 return const_name(
"None");
74 return make_caster<V>::Name;
76 template <
typename T_>
77 using Cast = movable_cast_t<T_>;
78 template <
typename T_>
79 static constexpr bool can_cast()
84 bool from_python(handle, uint32_t, cleanup_list*)
noexcept {
return false; }
86 template <
typename T_>
87 static handle from_cpp(T_&& r, rv_policy policy, cleanup_list* cleanup)
noexcept
97 if constexpr (std::is_void_v<V>)
98 return none().release();
100 return make_caster<V>::from_cpp(std::forward<T_>(r).unwrap_unchecked(), policy, cleanup);
C++ errors to Python exceptions: core's result / traced errors to the snicholls_core....
void set_python_error(const std::exception_ptr &p) noexcept
Sets the Python error for a C++ exception, by the file's table. For type casters, which return a null...
void raise_error(const E &e)
Throws e as the C++ exception that maps to the right Python class.