Skip to main content

Module strat

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.

StrategyMapped typeOk pathErr pathGDScript ergonomics
strat::Unexpected
Unexpected errors
Tval.clone()Default or
failed call
Sees T; ? works with any Error
()
Nil on error
Variantval.to_variant()nullif val == null
global::Error
Godot error enum
global::ErrorOK constantERR_* constantval == OK
(not provided)
Variant
Variantval.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 classwrap in classr.is_ok()
r.unwrap()

Structs§

Unexpected
Ergonomic catch-all error type for #[func] methods.