Module strat
Expand description
Built-in ErrorToGodot strategies for mapping Result<T, E> return types of #[func] methods.
This module is intended to be used qualified with strat:: module: strat::Unexpected etc.
It is re-exported in the prelude to enable this.
§Overview
Each type in this module implements ErrorToGodot with a different mapping strategy. Some strategies are not provided out-of-the-box
but could serve as inspiration to build your own. If you find any of those useful, let us know, and we may consider adding them.
| Strategy | Mapped type | Ok path | Err path | GDScript ergonomics |
|---|---|---|---|---|
strat::UnexpectedUnexpected errors | T | val.clone() | Default or failed call | Sees T; ? works with any Error |
()Nil on error | Variant | val.to_variant() | null | if val == null |
global::ErrorGodot error enum | global::Error | OK constant | ERR_* constant | val == OK |
(not provided)Variant | Variant | val.to_variant() | err.to_variant() | Must check type/value |
| (not provided) Dictionary ok/err | Dictionary<GString,Variant> | {"ok" => val} | {"err" => msg} | d.has("ok")d["ok"] |
| (not provided) Array 0/1 elems | Array<T> | [val] | [] | a.is_empty()a.front() – typed! |
| (not provided) Custom class | Gd<RustResult> | wrap in class | wrap in class | r.is_ok()r.unwrap() |
Structs§
- Unexpected
- Ergonomic catch-all error type for
#[func]methods.