Skip to main content

Crate duck_back

Crate duck_back 

Source
Expand description

§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.

Structs§

BevyResult
A wrapper around Result<T, E>.
The ? operator can be used to reduce this into ().
ERROR controls whether it raises an error when it gets reduced.

Traits§

Else
An extension trait that allows converting options and results into BevyResult.