pub trait IntoSignalMapEither: Sizedwhere
Self: SignalMap,{
// Provided methods
fn left_either<R>(self) -> SignalMapEither<Self, R>
where R: SignalMap { ... }
fn right_either<L>(self) -> SignalMapEither<L, Self>
where L: SignalMap { ... }
}Expand description
Blanket trait for transforming SignalMaps into SignalMapEither::Left or
SignalMapEither::Right.
Provided Methods§
Sourcefn left_either<R>(self) -> SignalMapEither<Self, R>where
R: SignalMap,
fn left_either<R>(self) -> SignalMapEither<Self, R>where
R: SignalMap,
Wrap this SignalMap in the SignalMapEither::Left variant.
Useful for conditional branching where different SignalMap types need to be returned
from the same function or closure, particularly with
.switch_signal_map.
§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;
#[derive(Resource)]
struct DoubleValues(bool);
let mut world = World::new();
world.insert_resource(DoubleValues(true));
let map = MutableBTreeMap::builder()
.values([(1, 10), (2, 20)])
.spawn(&mut world);
let signal = signal::from_system(|In(_), res: Res<DoubleValues>| res.0).switch_signal_map(
move |In(double): In<bool>, world: &mut World| {
if double {
map.signal_map()
.map_value(|In(v): In<i32>| v * 2)
.left_either()
} else {
map.signal_map().right_either()
}
},
);
// both branches produce compatible SignalMapEither typesSourcefn right_either<L>(self) -> SignalMapEither<L, Self>where
L: SignalMap,
fn right_either<L>(self) -> SignalMapEither<L, Self>where
L: SignalMap,
Wrap this SignalMap in the SignalMapEither::Right variant.
Useful for conditional branching where different SignalMap types need to be returned
from the same function or closure, particularly with
.switch_signal_map.
§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;
#[derive(Resource)]
struct MapSelector(bool);
let mut world = World::new();
world.insert_resource(MapSelector(false));
let map_a = MutableBTreeMap::builder()
.values([(1, 10), (2, 20)])
.spawn(&mut world);
let map_b = MutableBTreeMap::builder()
.values([(1, 100), (2, 200), (3, 300)])
.spawn(&mut world);
let signal = signal::from_system(|In(_), res: Res<MapSelector>| res.0).switch_signal_map(
move |In(use_a): In<bool>, world: &mut World| {
if use_a {
map_a
.signal_map()
.map_value(|In(v): In<i32>| v * 10)
.left_either()
} else {
map_b.signal_map().right_either()
}
},
);
// both branches produce compatible SignalMapEither typesDyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.