2 stable releases
Uses new Rust 2024
| new 1.1.0 | Apr 17, 2026 |
|---|---|
| 1.0.0 | Feb 16, 2026 |
#855 in Game dev
16KB
80 lines
Water Off a Duck's Back
Description:
Allows for easy error handling in bevy.
Warning: Darkness
This crate requires nightly, as it uses try_trait_v2 to convert from results and options to () using the ? operator.
It also uses try_as_dyn in order to prefer Display to Debug implementations when displaying an error.
I have little doubt that eventually in some form these features will be stabilised.
Example:
use bevy::{log::LogPlugin, prelude::*};
use duck_back::Else;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(LogPlugin {
filter: "duck_back=trace".to_string(),
..default()
}))
.add_systems(Startup, (start, query))
.run();
}
fn start() {
let bad: Option<u32> = None;
let _bad: u32 = bad.else_return()?;
}
fn query(transform: Query<&Transform>) {
let _transform: &Transform = transform.single().else_error()?;
}
2026-02-16T05:05:12.958909Z ERROR duck_back: (examples/messages.rs:20:5)
Failed to unwrap value.
No entities fit the query bevy_ecs::system::query::Query<'_, '_, &bevy_transform::components::transform::Transform>
2026-02-16T05:05:12.958934Z TRACE duck_back: (examples/messages.rs:16:5)
Failed to unwrap value.
Dependencies
~36MB
~656K SLoC