pub struct Commands<'w, 's> { /* private fields */ }Expand description
A Command queue to perform structural changes to the World.
Since each command requires exclusive access to the World,
all queued commands are automatically applied in sequence
when the ApplyDeferred system runs (see ApplyDeferred documentation for more details).
Each command can be used to modify the World in arbitrary ways:
- spawning or despawning entities
- inserting components on new or existing entities
- inserting resources
- etc.
For a version of Commands that works in parallel contexts (such as
within Query::par_iter) see
ParallelCommands
§Usage
Add mut commands: Commands as a function argument to your system to get a
copy of this struct that will be applied the next time a copy of ApplyDeferred runs.
Commands are almost always used as a SystemParam.
fn my_system(mut commands: Commands) {
// ...
}§Implementing
Each built-in command is implemented as a separate method, e.g. Commands::spawn.
In addition to the pre-defined command methods, you can add commands with any arbitrary
behavior using Commands::queue, which accepts any type implementing Command.
Since closures and other functions implement this trait automatically, this allows one-shot, anonymous custom commands.
// NOTE: type inference fails here, so annotations are required on the closure.
commands.queue(|w: &mut World| {
// Mutate the world however you want...
});§Error handling
A Command can return a Result,
which will be passed to an error handler if the Result is an error.
The default error handler panics. It can be configured via
the DefaultErrorHandler resource.
Alternatively, you can customize the error handler for a specific command
by calling Commands::queue_handled.
The error module provides some simple error handlers for convenience.
Implementations§
Source§impl<'w, 's> Commands<'w, 's>
impl<'w, 's> Commands<'w, 's>
Sourcepub fn new(queue: &'s mut CommandQueue, world: &'w World) -> Commands<'w, 's>
pub fn new(queue: &'s mut CommandQueue, world: &'w World) -> Commands<'w, 's>
Returns a new Commands instance from a CommandQueue and a World.
Sourcepub fn new_from_entities(
queue: &'s mut CommandQueue,
allocator: &'w EntityAllocator,
entities: &'w Entities,
) -> Commands<'w, 's>
pub fn new_from_entities( queue: &'s mut CommandQueue, allocator: &'w EntityAllocator, entities: &'w Entities, ) -> Commands<'w, 's>
Returns a new Commands instance from a CommandQueue and an Entities reference.
Sourcepub fn reborrow(&mut self) -> Commands<'w, '_>
pub fn reborrow(&mut self) -> Commands<'w, '_>
Returns a Commands with a smaller lifetime.
This is useful if you have &mut Commands but need Commands.
§Example
fn my_system(mut commands: Commands) {
// We do our initialization in a separate function,
// which expects an owned `Commands`.
do_initialization(commands.reborrow());
// Since we only reborrowed the commands instead of moving them, we can still use them.
commands.spawn_empty();
}Sourcepub fn append(&mut self, other: &mut CommandQueue)
pub fn append(&mut self, other: &mut CommandQueue)
Take all commands from other and append them to self, leaving other empty.
Sourcepub fn spawn_empty(&mut self) -> EntityCommands<'_>
pub fn spawn_empty(&mut self) -> EntityCommands<'_>
Spawns a new empty Entity and returns its corresponding EntityCommands.
§Example
#[derive(Component)]
struct Label(&'static str);
#[derive(Component)]
struct Strength(u32);
#[derive(Component)]
struct Agility(u32);
fn example_system(mut commands: Commands) {
// Create a new empty entity.
commands.spawn_empty();
// Create another empty entity.
commands.spawn_empty()
// Add a new component bundle to the entity.
.insert((Strength(1), Agility(2)))
// Add a single component to the entity.
.insert(Label("hello world"));
}§See also
spawnto spawn an entity with components.spawn_batchto spawn many entities with the same combination of components.
Sourcepub fn spawn<T>(&mut self, bundle: T) -> EntityCommands<'_>where
T: Bundle,
pub fn spawn<T>(&mut self, bundle: T) -> EntityCommands<'_>where
T: Bundle,
Spawns a new Entity with the given components
and returns the entity’s corresponding EntityCommands.
To spawn many entities with the same combination of components,
spawn_batch can be used for better performance.
§Example
#[derive(Component)]
struct ComponentA(u32);
#[derive(Component)]
struct ComponentB(u32);
#[derive(Bundle)]
struct ExampleBundle {
a: ComponentA,
b: ComponentB,
}
fn example_system(mut commands: Commands) {
// Create a new entity with a single component.
commands.spawn(ComponentA(1));
// Create a new entity with two components using a "tuple bundle".
commands.spawn((ComponentA(2), ComponentB(1)));
// Create a new entity with a component bundle.
commands.spawn(ExampleBundle {
a: ComponentA(3),
b: ComponentB(2),
});
}§See also
spawn_emptyto spawn an entity without any components.spawn_batchto spawn many entities with the same combination of components.
Examples found in repository?
More examples
20fn setup(mut commands: Commands) {
21 commands.spawn(Camera2d);
22 commands.spawn((
23 Text::new("Press P to panic"),
24 Node {
25 position_type: PositionType::Absolute,
26 top: px(12),
27 left: px(12),
28 ..default()
29 },
30 ));
31}- examples/window/screenshot.rs
- examples/gltf/gltf_skinned_mesh.rs
- examples/2d/sprite_tile.rs
- examples/shader/shader_material_2d.rs
- examples/shader/shader_material_wesl.rs
- examples/shader/fallback_image.rs
- examples/dev_tools/fps_overlay.rs
- examples/shader/shader_material.rs
- examples/shader/shader_material_glsl.rs
- examples/asset/extra_source.rs
- examples/ui/window_fallthrough.rs
- examples/asset/hot_asset_reloading.rs
- examples/audio/audio_control.rs
- examples/shader_advanced/custom_vertex_attribute.rs
- examples/ui/font_atlas_debug.rs
- examples/gltf/load_gltf_extras.rs
- examples/asset/embedded_asset.rs
- examples/window/scale_factor_override.rs
- examples/2d/sprite_sheet.rs
- examples/3d/parenting.rs
- examples/remote/server.rs
- examples/3d/animated_material.rs
- examples/gltf/load_gltf.rs
- examples/gltf/update_gltf_scene.rs
- examples/shader/storage_buffer.rs
- examples/ui/virtual_keyboard.rs
- examples/3d/vertex_colors.rs
- examples/3d/spherical_area_lights.rs
- examples/2d/bloom_2d.rs
- examples/ui/ui_texture_slice.rs
- examples/ui/ui_texture_slice_flip_and_tile.rs
- examples/picking/dragdrop_picking.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/2d/mesh2d_alpha_mode.rs
- examples/asset/asset_settings.rs
- examples/2d/mesh2d_repeated_texture.rs
- examples/ui/tab_navigation.rs
- examples/ui/z_index.rs
- examples/ui/ui_drag_and_drop.rs
- examples/animation/animated_transform.rs
Sourcepub fn entity(&mut self, entity: Entity) -> EntityCommands<'_>
pub fn entity(&mut self, entity: Entity) -> EntityCommands<'_>
Returns the EntityCommands for the given Entity.
This method does not guarantee that commands queued by the returned EntityCommands
will be successful, since the entity could be despawned before they are executed.
§Example
#[derive(Resource)]
struct PlayerEntity {
entity: Entity
}
#[derive(Component)]
struct Label(&'static str);
fn example_system(mut commands: Commands, player: Res<PlayerEntity>) {
// Get the entity and add a component.
commands.entity(player.entity).insert(Label("hello world"));
}§See also
get_entityfor the fallible version.
Examples found in repository?
More examples
31fn screenshot_saving(
32 mut commands: Commands,
33 screenshot_saving: Query<Entity, With<Capturing>>,
34 window: Single<Entity, With<Window>>,
35) {
36 match screenshot_saving.iter().count() {
37 0 => {
38 commands.entity(*window).remove::<CursorIcon>();
39 }
40 x if x > 0 => {
41 commands
42 .entity(*window)
43 .insert(CursorIcon::from(SystemCursorIcon::Progress));
44 }
45 _ => {}
46 }
47}48fn focus_system(
49 mut commands: Commands,
50 focus: Res<InputFocus>,
51 mut query: Query<Entity, With<Button>>,
52) {
53 if focus.is_changed() {
54 for button in query.iter_mut() {
55 if focus.0 == Some(button) {
56 commands.entity(button).insert(Outline {
57 color: Color::WHITE,
58 width: px(2),
59 offset: px(2),
60 });
61 } else {
62 commands.entity(button).remove::<Outline>();
63 }
64 }
65 }
66}138fn on_drag_drop(
139 mut event: On<Pointer<DragDrop>>,
140 button: Single<Entity, With<DraggableButton>>,
141 mut commands: Commands,
142 ghost: Single<Entity, With<GhostPreview>>,
143 mut meshes: ResMut<Assets<Mesh>>,
144 mut materials: ResMut<Assets<ColorMaterial>>,
145) {
146 if event.dropped == *button {
147 commands.entity(*ghost).despawn();
148 let Some(position) = event.hit.position else {
149 return;
150 };
151 commands.spawn((
152 DroppedElement,
153 Mesh2d(meshes.add(Circle::new(ELEMENT_SIZE))),
154 MeshMaterial2d(materials.add(Color::srgb(1.0, 1.0, 0.6))),
155 Transform::from_translation(position + 2. * Vec3::Z),
156 Pickable::IGNORE,
157 ));
158 event.propagate(false);
159 }
160}
161
162fn on_drag_leave(
163 mut event: On<Pointer<DragLeave>>,
164 button: Single<Entity, With<DraggableButton>>,
165 mut commands: Commands,
166 ghost: Single<Entity, With<GhostPreview>>,
167) {
168 if event.dragged == *button {
169 commands.entity(*ghost).despawn();
170 event.propagate(false);
171 }
172}72fn update_bloom_settings(
73 camera: Single<(Entity, &Tonemapping, Option<&mut Bloom>), With<Camera>>,
74 mut text: Single<&mut Text>,
75 mut commands: Commands,
76 keycode: Res<ButtonInput<KeyCode>>,
77 time: Res<Time>,
78) {
79 let (camera_entity, tonemapping, bloom) = camera.into_inner();
80
81 match bloom {
82 Some(mut bloom) => {
83 text.0 = "Bloom (Toggle: Space)\n".to_string();
84 text.push_str(&format!("(Q/A) Intensity: {:.2}\n", bloom.intensity));
85 text.push_str(&format!(
86 "(W/S) Low-frequency boost: {:.2}\n",
87 bloom.low_frequency_boost
88 ));
89 text.push_str(&format!(
90 "(E/D) Low-frequency boost curvature: {:.2}\n",
91 bloom.low_frequency_boost_curvature
92 ));
93 text.push_str(&format!(
94 "(R/F) High-pass frequency: {:.2}\n",
95 bloom.high_pass_frequency
96 ));
97 text.push_str(&format!(
98 "(T/G) Mode: {}\n",
99 match bloom.composite_mode {
100 BloomCompositeMode::EnergyConserving => "Energy-conserving",
101 BloomCompositeMode::Additive => "Additive",
102 }
103 ));
104 text.push_str(&format!(
105 "(Y/H) Threshold: {:.2}\n",
106 bloom.prefilter.threshold
107 ));
108 text.push_str(&format!(
109 "(U/J) Threshold softness: {:.2}\n",
110 bloom.prefilter.threshold_softness
111 ));
112 text.push_str(&format!("(I/K) Horizontal Scale: {:.2}\n", bloom.scale.x));
113
114 if keycode.just_pressed(KeyCode::Space) {
115 commands.entity(camera_entity).remove::<Bloom>();
116 }
117
118 let dt = time.delta_secs();
119
120 if keycode.pressed(KeyCode::KeyA) {
121 bloom.intensity -= dt / 10.0;
122 }
123 if keycode.pressed(KeyCode::KeyQ) {
124 bloom.intensity += dt / 10.0;
125 }
126 bloom.intensity = bloom.intensity.clamp(0.0, 1.0);
127
128 if keycode.pressed(KeyCode::KeyS) {
129 bloom.low_frequency_boost -= dt / 10.0;
130 }
131 if keycode.pressed(KeyCode::KeyW) {
132 bloom.low_frequency_boost += dt / 10.0;
133 }
134 bloom.low_frequency_boost = bloom.low_frequency_boost.clamp(0.0, 1.0);
135
136 if keycode.pressed(KeyCode::KeyD) {
137 bloom.low_frequency_boost_curvature -= dt / 10.0;
138 }
139 if keycode.pressed(KeyCode::KeyE) {
140 bloom.low_frequency_boost_curvature += dt / 10.0;
141 }
142 bloom.low_frequency_boost_curvature =
143 bloom.low_frequency_boost_curvature.clamp(0.0, 1.0);
144
145 if keycode.pressed(KeyCode::KeyF) {
146 bloom.high_pass_frequency -= dt / 10.0;
147 }
148 if keycode.pressed(KeyCode::KeyR) {
149 bloom.high_pass_frequency += dt / 10.0;
150 }
151 bloom.high_pass_frequency = bloom.high_pass_frequency.clamp(0.0, 1.0);
152
153 if keycode.pressed(KeyCode::KeyG) {
154 bloom.composite_mode = BloomCompositeMode::Additive;
155 }
156 if keycode.pressed(KeyCode::KeyT) {
157 bloom.composite_mode = BloomCompositeMode::EnergyConserving;
158 }
159
160 if keycode.pressed(KeyCode::KeyH) {
161 bloom.prefilter.threshold -= dt;
162 }
163 if keycode.pressed(KeyCode::KeyY) {
164 bloom.prefilter.threshold += dt;
165 }
166 bloom.prefilter.threshold = bloom.prefilter.threshold.max(0.0);
167
168 if keycode.pressed(KeyCode::KeyJ) {
169 bloom.prefilter.threshold_softness -= dt / 10.0;
170 }
171 if keycode.pressed(KeyCode::KeyU) {
172 bloom.prefilter.threshold_softness += dt / 10.0;
173 }
174 bloom.prefilter.threshold_softness = bloom.prefilter.threshold_softness.clamp(0.0, 1.0);
175
176 if keycode.pressed(KeyCode::KeyK) {
177 bloom.scale.x -= dt * 2.0;
178 }
179 if keycode.pressed(KeyCode::KeyI) {
180 bloom.scale.x += dt * 2.0;
181 }
182 bloom.scale.x = bloom.scale.x.clamp(0.0, 16.0);
183 }
184
185 None => {
186 text.0 = "Bloom: Off (Toggle: Space)\n".to_string();
187
188 if keycode.just_pressed(KeyCode::Space) {
189 commands.entity(camera_entity).insert(Bloom::default());
190 }
191 }
192 }
193
194 text.push_str(&format!("(O) Tonemapping: {tonemapping:?}\n"));
195 if keycode.just_pressed(KeyCode::KeyO) {
196 commands
197 .entity(camera_entity)
198 .insert(next_tonemap(tonemapping));
199 }
200}22fn setup(
23 mut commands: Commands,
24 mut meshes: ResMut<Assets<Mesh>>,
25 mut materials: ResMut<Assets<StandardMaterial>>,
26 mut animations: ResMut<Assets<AnimationClip>>,
27 mut graphs: ResMut<Assets<AnimationGraph>>,
28) {
29 // Camera
30 commands.spawn((
31 Camera3d::default(),
32 Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
33 ));
34
35 // Light
36 commands.spawn((
37 PointLight {
38 intensity: 500_000.0,
39 ..default()
40 },
41 Transform::from_xyz(0.0, 2.5, 0.0),
42 ));
43
44 // Let's use the `Name` component to target entities. We can use anything we
45 // like, but names are convenient.
46 let planet = Name::new("planet");
47 let orbit_controller = Name::new("orbit_controller");
48 let satellite = Name::new("satellite");
49
50 // Creating the animation
51 let mut animation = AnimationClip::default();
52 // A curve can modify a single part of a transform: here, the translation.
53 let planet_animation_target_id = AnimationTargetId::from_name(&planet);
54 animation.add_curve_to_target(
55 planet_animation_target_id,
56 AnimatableCurve::new(
57 animated_field!(Transform::translation),
58 UnevenSampleAutoCurve::new([0.0, 1.0, 2.0, 3.0, 4.0].into_iter().zip([
59 Vec3::new(1.0, 0.0, 1.0),
60 Vec3::new(-1.0, 0.0, 1.0),
61 Vec3::new(-1.0, 0.0, -1.0),
62 Vec3::new(1.0, 0.0, -1.0),
63 // in case seamless looping is wanted, the last keyframe should
64 // be the same as the first one
65 Vec3::new(1.0, 0.0, 1.0),
66 ]))
67 .expect("should be able to build translation curve because we pass in valid samples"),
68 ),
69 );
70 // Or it can modify the rotation of the transform.
71 // To find the entity to modify, the hierarchy will be traversed looking for
72 // an entity with the right name at each level.
73 let orbit_controller_animation_target_id =
74 AnimationTargetId::from_names([planet.clone(), orbit_controller.clone()].iter());
75 animation.add_curve_to_target(
76 orbit_controller_animation_target_id,
77 AnimatableCurve::new(
78 animated_field!(Transform::rotation),
79 UnevenSampleAutoCurve::new([0.0, 1.0, 2.0, 3.0, 4.0].into_iter().zip([
80 Quat::IDENTITY,
81 Quat::from_axis_angle(Vec3::Y, PI / 2.),
82 Quat::from_axis_angle(Vec3::Y, PI / 2. * 2.),
83 Quat::from_axis_angle(Vec3::Y, PI / 2. * 3.),
84 Quat::IDENTITY,
85 ]))
86 .expect("Failed to build rotation curve"),
87 ),
88 );
89 // If a curve in an animation is shorter than the other, it will not repeat
90 // until all other curves are finished. In that case, another animation should
91 // be created for each part that would have a different duration / period.
92 let satellite_animation_target_id = AnimationTargetId::from_names(
93 [planet.clone(), orbit_controller.clone(), satellite.clone()].iter(),
94 );
95 animation.add_curve_to_target(
96 satellite_animation_target_id,
97 AnimatableCurve::new(
98 animated_field!(Transform::scale),
99 UnevenSampleAutoCurve::new(
100 [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
101 .into_iter()
102 .zip([
103 Vec3::splat(0.8),
104 Vec3::splat(1.2),
105 Vec3::splat(0.8),
106 Vec3::splat(1.2),
107 Vec3::splat(0.8),
108 Vec3::splat(1.2),
109 Vec3::splat(0.8),
110 Vec3::splat(1.2),
111 Vec3::splat(0.8),
112 ]),
113 )
114 .expect("Failed to build scale curve"),
115 ),
116 );
117 // There can be more than one curve targeting the same entity path.
118 animation.add_curve_to_target(
119 AnimationTargetId::from_names(
120 [planet.clone(), orbit_controller.clone(), satellite.clone()].iter(),
121 ),
122 AnimatableCurve::new(
123 animated_field!(Transform::rotation),
124 UnevenSampleAutoCurve::new([0.0, 1.0, 2.0, 3.0, 4.0].into_iter().zip([
125 Quat::IDENTITY,
126 Quat::from_axis_angle(Vec3::Y, PI / 2.),
127 Quat::from_axis_angle(Vec3::Y, PI / 2. * 2.),
128 Quat::from_axis_angle(Vec3::Y, PI / 2. * 3.),
129 Quat::IDENTITY,
130 ]))
131 .expect("should be able to build translation curve because we pass in valid samples"),
132 ),
133 );
134
135 // Create the animation graph
136 let (graph, animation_index) = AnimationGraph::from_clip(animations.add(animation));
137
138 // Create the animation player, and set it to repeat
139 let mut player = AnimationPlayer::default();
140 player.play(animation_index).repeat();
141
142 // Create the scene that will be animated
143 // First entity is the planet
144 let planet_entity = commands
145 .spawn((
146 Mesh3d(meshes.add(Sphere::default())),
147 MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
148 // Add the animation graph and player
149 planet,
150 AnimationGraphHandle(graphs.add(graph)),
151 player,
152 ))
153 .id();
154 commands.entity(planet_entity).insert((
155 planet_animation_target_id,
156 AnimatedBy(planet_entity),
157 children![(
158 Transform::default(),
159 Visibility::default(),
160 orbit_controller,
161 orbit_controller_animation_target_id,
162 AnimatedBy(planet_entity),
163 children![(
164 Mesh3d(meshes.add(Cuboid::new(0.5, 0.5, 0.5))),
165 MeshMaterial3d(materials.add(Color::srgb(0.3, 0.9, 0.3))),
166 Transform::from_xyz(1.5, 0.0, 0.0),
167 satellite_animation_target_id,
168 AnimatedBy(planet_entity),
169 satellite,
170 )],
171 )],
172 ));
173}Sourcepub fn get_entity(
&mut self,
entity: Entity,
) -> Result<EntityCommands<'_>, InvalidEntityError>
pub fn get_entity( &mut self, entity: Entity, ) -> Result<EntityCommands<'_>, InvalidEntityError>
Returns the EntityCommands for the requested Entity if it is valid.
This method does not guarantee that commands queued by the returned EntityCommands
will be successful, since the entity could be despawned before they are executed.
This also does not error when the entity has not been spawned.
For that behavior, see get_spawned_entity,
which should be preferred for accessing entities you expect to already be spawned, like those found from a query.
For details on entity spawning vs validity, see entity module docs.
§Errors
Returns InvalidEntityError if the requested entity does not exist.
§Example
#[derive(Resource)]
struct PlayerEntity {
entity: Entity
}
#[derive(Component)]
struct Label(&'static str);
fn example_system(mut commands: Commands, player: Res<PlayerEntity>) -> Result {
// Get the entity if it still exists and store the `EntityCommands`.
// If it doesn't exist, the `?` operator will propagate the returned error
// to the system, and the system will pass it to an error handler.
let mut entity_commands = commands.get_entity(player.entity)?;
// Add a component to the entity.
entity_commands.insert(Label("hello world"));
// Return from the system successfully.
Ok(())
}§See also
entityfor the infallible version.
Sourcepub fn get_spawned_entity(
&mut self,
entity: Entity,
) -> Result<EntityCommands<'_>, EntityNotSpawnedError>
pub fn get_spawned_entity( &mut self, entity: Entity, ) -> Result<EntityCommands<'_>, EntityNotSpawnedError>
Returns the EntityCommands for the requested Entity if it spawned in the world now.
Note that for entities that have not been spawned yet, like ones from spawn, this will error.
If that is not desired, try get_entity.
This should be used over get_entity when you expect the entity to already be spawned in the world.
If the entity is valid but not yet spawned, this will error that information, where get_entity would succeed, leading to potentially surprising results.
For details on entity spawning vs validity, see entity module docs.
This method does not guarantee that commands queued by the returned EntityCommands
will be successful, since the entity could be despawned before they are executed.
§Errors
Returns EntityNotSpawnedError if the requested entity does not exist.
§Example
#[derive(Resource)]
struct PlayerEntity {
entity: Entity
}
#[derive(Component)]
struct Label(&'static str);
fn example_system(mut commands: Commands, player: Res<PlayerEntity>) -> Result {
// Get the entity if it still exists and store the `EntityCommands`.
// If it doesn't exist, the `?` operator will propagate the returned error
// to the system, and the system will pass it to an error handler.
let mut entity_commands = commands.get_spawned_entity(player.entity)?;
// Add a component to the entity.
entity_commands.insert(Label("hello world"));
// Return from the system successfully.
Ok(())
}§See also
entityfor the infallible version.
Sourcepub fn spawn_batch<I>(&mut self, batch: I)where
I: IntoIterator + Send + Sync + 'static,
<I as IntoIterator>::Item: Bundle,
<<I as IntoIterator>::Item as DynamicBundle>::Effect: NoBundleEffect,
pub fn spawn_batch<I>(&mut self, batch: I)where
I: IntoIterator + Send + Sync + 'static,
<I as IntoIterator>::Item: Bundle,
<<I as IntoIterator>::Item as DynamicBundle>::Effect: NoBundleEffect,
Spawns multiple entities with the same combination of components,
based on a batch of Bundles.
A batch can be any type that implements IntoIterator and contains bundles,
such as a Vec<Bundle> or an array [Bundle; N].
This method is equivalent to iterating the batch
and calling spawn for each bundle,
but is faster by pre-allocating memory and having exclusive World access.
§Example
use bevy_ecs::prelude::*;
#[derive(Component)]
struct Score(u32);
fn example_system(mut commands: Commands) {
commands.spawn_batch([
(Name::new("Alice"), Score(0)),
(Name::new("Bob"), Score(0)),
]);
}§See also
spawnto spawn an entity with components.spawn_emptyto spawn an entity without components.
Sourcepub fn queue<C, T>(&mut self, command: C)where
C: Command<T> + HandleError<T>,
pub fn queue<C, T>(&mut self, command: C)where
C: Command<T> + HandleError<T>,
Pushes a generic Command to the command queue.
If the Command returns a Result,
it will be handled using the default error handler.
To use a custom error handler, see Commands::queue_handled.
The command can be:
- A custom struct that implements
Command. - A closure or function that matches one of the following signatures:
- A built-in command from the
commandmodule.
§Example
#[derive(Resource, Default)]
struct Counter(u64);
struct AddToCounter(String);
impl Command<Result> for AddToCounter {
fn apply(self, world: &mut World) -> Result {
let mut counter = world.get_resource_or_insert_with(Counter::default);
let amount: u64 = self.0.parse()?;
counter.0 += amount;
Ok(())
}
}
fn add_three_to_counter_system(mut commands: Commands) {
commands.queue(AddToCounter("3".to_string()));
}
fn add_twenty_five_to_counter_system(mut commands: Commands) {
commands.queue(|world: &mut World| {
let mut counter = world.get_resource_or_insert_with(Counter::default);
counter.0 += 25;
});
}Sourcepub fn queue_handled<C, T>(
&mut self,
command: C,
error_handler: fn(BevyError, ErrorContext),
)where
C: Command<T> + HandleError<T>,
pub fn queue_handled<C, T>(
&mut self,
command: C,
error_handler: fn(BevyError, ErrorContext),
)where
C: Command<T> + HandleError<T>,
Pushes a generic Command to the command queue.
If the Command returns a Result,
the given error_handler will be used to handle error cases.
To implicitly use the default error handler, see Commands::queue.
The command can be:
- A custom struct that implements
Command. - A closure or function that matches one of the following signatures:
- A built-in command from the
commandmodule.
§Example
use bevy_ecs::error::warn;
#[derive(Resource, Default)]
struct Counter(u64);
struct AddToCounter(String);
impl Command<Result> for AddToCounter {
fn apply(self, world: &mut World) -> Result {
let mut counter = world.get_resource_or_insert_with(Counter::default);
let amount: u64 = self.0.parse()?;
counter.0 += amount;
Ok(())
}
}
fn add_three_to_counter_system(mut commands: Commands) {
commands.queue_handled(AddToCounter("3".to_string()), warn);
}
fn add_twenty_five_to_counter_system(mut commands: Commands) {
commands.queue(|world: &mut World| {
let mut counter = world.get_resource_or_insert_with(Counter::default);
counter.0 += 25;
});
}Sourcepub fn queue_silenced<C, T>(&mut self, command: C)where
C: Command<T> + HandleError<T>,
pub fn queue_silenced<C, T>(&mut self, command: C)where
C: Command<T> + HandleError<T>,
Pushes a generic Command to the queue like Commands::queue_handled, but instead silently ignores any errors.
Sourcepub fn insert_batch<I, B>(&mut self, batch: I)where
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
B: Bundle,
<B as DynamicBundle>::Effect: NoBundleEffect,
pub fn insert_batch<I, B>(&mut self, batch: I)where
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
B: Bundle,
<B as DynamicBundle>::Effect: NoBundleEffect,
Adds a series of Bundles to each Entity they are paired with,
based on a batch of (Entity, Bundle) pairs.
A batch can be any type that implements IntoIterator
and contains (Entity, Bundle) tuples,
such as a Vec<(Entity, Bundle)>
or an array [(Entity, Bundle); N].
This will overwrite any pre-existing components shared by the Bundle type.
Use Commands::insert_batch_if_new to keep the pre-existing components instead.
This method is equivalent to iterating the batch
and calling insert for each pair,
but is faster by caching data that is shared between entities.
§Fallible
This command will fail if any of the given entities do not exist.
It will internally return a TryInsertBatchError,
which will be handled by the default error handler.
Sourcepub fn insert_batch_if_new<I, B>(&mut self, batch: I)where
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
B: Bundle,
<B as DynamicBundle>::Effect: NoBundleEffect,
pub fn insert_batch_if_new<I, B>(&mut self, batch: I)where
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
B: Bundle,
<B as DynamicBundle>::Effect: NoBundleEffect,
Adds a series of Bundles to each Entity they are paired with,
based on a batch of (Entity, Bundle) pairs.
A batch can be any type that implements IntoIterator
and contains (Entity, Bundle) tuples,
such as a Vec<(Entity, Bundle)>
or an array [(Entity, Bundle); N].
This will keep any pre-existing components shared by the Bundle type
and discard the new values.
Use Commands::insert_batch to overwrite the pre-existing components instead.
This method is equivalent to iterating the batch
and calling insert_if_new for each pair,
but is faster by caching data that is shared between entities.
§Fallible
This command will fail if any of the given entities do not exist.
It will internally return a TryInsertBatchError,
which will be handled by the default error handler.
Sourcepub fn try_insert_batch<I, B>(&mut self, batch: I)where
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
B: Bundle,
<B as DynamicBundle>::Effect: NoBundleEffect,
pub fn try_insert_batch<I, B>(&mut self, batch: I)where
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
B: Bundle,
<B as DynamicBundle>::Effect: NoBundleEffect,
Adds a series of Bundles to each Entity they are paired with,
based on a batch of (Entity, Bundle) pairs.
A batch can be any type that implements IntoIterator
and contains (Entity, Bundle) tuples,
such as a Vec<(Entity, Bundle)>
or an array [(Entity, Bundle); N].
This will overwrite any pre-existing components shared by the Bundle type.
Use Commands::try_insert_batch_if_new to keep the pre-existing components instead.
This method is equivalent to iterating the batch
and calling insert for each pair,
but is faster by caching data that is shared between entities.
§Fallible
This command will fail if any of the given entities do not exist.
It will internally return a TryInsertBatchError,
which will be handled by logging the error at the warn level.
Sourcepub fn try_insert_batch_if_new<I, B>(&mut self, batch: I)where
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
B: Bundle,
<B as DynamicBundle>::Effect: NoBundleEffect,
pub fn try_insert_batch_if_new<I, B>(&mut self, batch: I)where
I: IntoIterator<Item = (Entity, B)> + Send + Sync + 'static,
B: Bundle,
<B as DynamicBundle>::Effect: NoBundleEffect,
Adds a series of Bundles to each Entity they are paired with,
based on a batch of (Entity, Bundle) pairs.
A batch can be any type that implements IntoIterator
and contains (Entity, Bundle) tuples,
such as a Vec<(Entity, Bundle)>
or an array [(Entity, Bundle); N].
This will keep any pre-existing components shared by the Bundle type
and discard the new values.
Use Commands::try_insert_batch to overwrite the pre-existing components instead.
This method is equivalent to iterating the batch
and calling insert_if_new for each pair,
but is faster by caching data that is shared between entities.
§Fallible
This command will fail if any of the given entities do not exist.
It will internally return a TryInsertBatchError,
which will be handled by logging the error at the warn level.
Sourcepub fn init_resource<R>(&mut self)
pub fn init_resource<R>(&mut self)
Inserts a Resource into the World with an inferred value.
The inferred value is determined by the FromWorld trait of the resource.
Note that any resource with the Default trait automatically implements FromWorld,
and those default values will be used.
If the resource already exists when the command is applied, nothing happens.
§Example
#[derive(Resource, Default)]
struct Scoreboard {
current_score: u32,
high_score: u32,
}
fn initialize_scoreboard(mut commands: Commands) {
commands.init_resource::<Scoreboard>();
}Sourcepub fn insert_resource<R>(&mut self, resource: R)where
R: Resource,
pub fn insert_resource<R>(&mut self, resource: R)where
R: Resource,
Inserts a Resource into the World with a specific value.
This will overwrite any previous value of the same resource type.
§Example
#[derive(Resource)]
struct Scoreboard {
current_score: u32,
high_score: u32,
}
fn system(mut commands: Commands) {
commands.insert_resource(Scoreboard {
current_score: 0,
high_score: 0,
});
}Examples found in repository?
21fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
22 commands.spawn(Camera2d);
23
24 commands.insert_resource(AnimationState {
25 min: 128.0,
26 max: 512.0,
27 current: 128.0,
28 speed: 50.0,
29 });
30 commands.spawn(Sprite {
31 image: asset_server.load("branding/icon.png"),
32 image_mode: SpriteImageMode::Tiled {
33 tile_x: true,
34 tile_y: true,
35 stretch_value: 0.5, // The image will tile every 128px
36 },
37 ..default()
38 });
39}More examples
26fn setup(
27 mut commands: Commands,
28 mut meshes: ResMut<Assets<Mesh>>,
29 mut materials: ResMut<Assets<StandardMaterial>>,
30) {
31 // circular base
32 commands.spawn((
33 Mesh3d(meshes.add(Circle::new(4.0))),
34 MeshMaterial3d(materials.add(Color::WHITE)),
35 Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
36 ));
37
38 // cube
39 commands.spawn((
40 Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
41 MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
42 Transform::from_xyz(0.0, 0.5, 0.0),
43 Cube(1.0),
44 ));
45
46 // test resource
47 commands.insert_resource(TestResource {
48 foo: Vec2::new(1.0, -1.0),
49 bar: false,
50 });
51
52 // light
53 commands.spawn((
54 PointLight {
55 shadows_enabled: true,
56 ..default()
57 },
58 Transform::from_xyz(4.0, 8.0, 4.0),
59 ));
60
61 // camera
62 commands.spawn((
63 Camera3d::default(),
64 Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
65 ));
66}83fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut state: ResMut<State>) {
84 let font_handle = asset_server.load("fonts/FiraSans-Bold.ttf");
85 state.handle = font_handle.clone();
86 commands.spawn(Camera2d);
87 commands
88 .spawn((
89 Node {
90 position_type: PositionType::Absolute,
91 bottom: Val::ZERO,
92 ..default()
93 },
94 BackgroundColor(Color::NONE),
95 ))
96 .with_children(|parent| {
97 parent.spawn((
98 Text::new("a"),
99 TextFont {
100 font: font_handle,
101 font_size: 50.0,
102 ..default()
103 },
104 TextColor(YELLOW.into()),
105 ));
106 });
107 // We're seeding the PRNG here to make this example deterministic for testing purposes.
108 // This isn't strictly required in practical use unless you need your app to be deterministic.
109 commands.insert_resource(SeededRng(ChaCha8Rng::seed_from_u64(19878367467713)));
110}21fn setup(
22 mut commands: Commands,
23 mut meshes: ResMut<Assets<Mesh>>,
24 mut buffers: ResMut<Assets<ShaderStorageBuffer>>,
25 mut materials: ResMut<Assets<CustomMaterial>>,
26) {
27 // Example data for the storage buffer
28 let color_data: Vec<[f32; 4]> = vec![
29 [1.0, 0.0, 0.0, 1.0],
30 [0.0, 1.0, 0.0, 1.0],
31 [0.0, 0.0, 1.0, 1.0],
32 [1.0, 1.0, 0.0, 1.0],
33 [0.0, 1.0, 1.0, 1.0],
34 ];
35
36 let colors = buffers.add(ShaderStorageBuffer::from(color_data));
37
38 let mesh_handle = meshes.add(Cuboid::from_size(Vec3::splat(0.3)));
39 // Create the custom material with the storage buffer
40 let material_handle = materials.add(CustomMaterial {
41 colors: colors.clone(),
42 });
43
44 commands.insert_resource(CustomMaterialHandle(material_handle.clone()));
45
46 // Spawn cubes with the custom material
47 let mut current_color_id: u32 = 0;
48 for i in -6..=6 {
49 for j in -3..=3 {
50 commands.spawn((
51 Mesh3d(mesh_handle.clone()),
52 MeshMaterial3d(material_handle.clone()),
53 MeshTag(current_color_id % 5),
54 Transform::from_xyz(i as f32, j as f32, 0.0),
55 ));
56 current_color_id += 1;
57 }
58 }
59
60 // Camera
61 commands.spawn((
62 Camera3d::default(),
63 Transform::from_xyz(0.0, 0.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
64 ));
65}Sourcepub fn remove_resource<R>(&mut self)where
R: Resource,
pub fn remove_resource<R>(&mut self)where
R: Resource,
Sourcepub fn run_system(&mut self, id: SystemId)
pub fn run_system(&mut self, id: SystemId)
Runs the system corresponding to the given SystemId.
Before running a system, it must first be registered via
Commands::register_system or World::register_system.
The system is run in an exclusive and single-threaded way. Running slow systems can become a bottleneck.
There is no way to get the output of a system when run as a command, because the
execution of the system happens later. To get the output of a system, use
World::run_system or World::run_system_with instead of running the system as a command.
§Fallible
This command will fail if the given SystemId
does not correspond to a System.
It will internally return a RegisteredSystemError,
which will be handled by logging the error at the warn level.
Sourcepub fn run_system_with<I>(
&mut self,
id: SystemId<I>,
input: <I as SystemInput>::Inner<'static>,
)
pub fn run_system_with<I>( &mut self, id: SystemId<I>, input: <I as SystemInput>::Inner<'static>, )
Runs the system corresponding to the given SystemId with input.
Before running a system, it must first be registered via
Commands::register_system or World::register_system.
The system is run in an exclusive and single-threaded way. Running slow systems can become a bottleneck.
There is no way to get the output of a system when run as a command, because the
execution of the system happens later. To get the output of a system, use
World::run_system or World::run_system_with instead of running the system as a command.
§Fallible
This command will fail if the given SystemId
does not correspond to a System.
It will internally return a RegisteredSystemError,
which will be handled by logging the error at the warn level.
Sourcepub fn register_system<I, O, M>(
&mut self,
system: impl IntoSystem<I, O, M> + 'static,
) -> SystemId<I, O>
pub fn register_system<I, O, M>( &mut self, system: impl IntoSystem<I, O, M> + 'static, ) -> SystemId<I, O>
Registers a system and returns its SystemId so it can later be called by
Commands::run_system or World::run_system.
This is different from adding systems to a Schedule,
because the SystemId that is returned can be used anywhere in the World to run the associated system.
Using a Schedule is still preferred for most cases
due to its better performance and ability to run non-conflicting systems simultaneously.
§Note
If the same system is registered more than once,
each registration will be considered a different system,
and they will each be given their own SystemId.
If you want to avoid registering the same system multiple times,
consider using Commands::run_system_cached or storing the SystemId
in a Local.
§Example
#[derive(Resource)]
struct Counter(i32);
fn register_system(
mut commands: Commands,
mut local_system: Local<Option<SystemId>>,
) {
if let Some(system) = *local_system {
commands.run_system(system);
} else {
*local_system = Some(commands.register_system(increment_counter));
}
}
fn increment_counter(mut value: ResMut<Counter>) {
value.0 += 1;
}
Sourcepub fn unregister_system<I, O>(&mut self, system_id: SystemId<I, O>)
pub fn unregister_system<I, O>(&mut self, system_id: SystemId<I, O>)
Removes a system previously registered with Commands::register_system
or World::register_system.
After removing a system, the SystemId becomes invalid
and attempting to use it afterwards will result in an error.
Re-adding the removed system will register it with a new SystemId.
§Fallible
This command will fail if the given SystemId
does not correspond to a System.
It will internally return a RegisteredSystemError,
which will be handled by logging the error at the warn level.
Sourcepub fn unregister_system_cached<I, O, M, S>(&mut self, system: S)where
I: SystemInput + Send + 'static,
O: 'static,
M: 'static,
S: IntoSystem<I, O, M> + Send + 'static,
pub fn unregister_system_cached<I, O, M, S>(&mut self, system: S)where
I: SystemInput + Send + 'static,
O: 'static,
M: 'static,
S: IntoSystem<I, O, M> + Send + 'static,
Removes a system previously registered with one of the following:
§Fallible
This command will fail if the given system
is not currently cached in a CachedSystemId resource.
It will internally return a RegisteredSystemError,
which will be handled by logging the error at the warn level.
Sourcepub fn run_system_cached<M, S>(&mut self, system: S)
pub fn run_system_cached<M, S>(&mut self, system: S)
Runs a cached system, registering it if necessary.
Unlike Commands::run_system, this method does not require manual registration.
The first time this method is called for a particular system,
it will register the system and store its SystemId in a
CachedSystemId resource for later.
If you would rather manage the SystemId yourself,
or register multiple copies of the same system,
use Commands::register_system instead.
§Limitations
This method only accepts ZST (zero-sized) systems to guarantee that any two systems of the same type must be equal. This means that closures that capture the environment, and function pointers, are not accepted.
If you want to access values from the environment within a system,
consider passing them in as inputs via Commands::run_system_cached_with.
If that’s not an option, consider Commands::register_system instead.
Sourcepub fn run_system_cached_with<I, M, S>(
&mut self,
system: S,
input: <I as SystemInput>::Inner<'static>,
)where
I: SystemInput + Send + 'static,
<I as SystemInput>::Inner<'static>: Send,
M: 'static,
S: IntoSystem<I, (), M> + Send + 'static,
pub fn run_system_cached_with<I, M, S>(
&mut self,
system: S,
input: <I as SystemInput>::Inner<'static>,
)where
I: SystemInput + Send + 'static,
<I as SystemInput>::Inner<'static>: Send,
M: 'static,
S: IntoSystem<I, (), M> + Send + 'static,
Runs a cached system with an input, registering it if necessary.
Unlike Commands::run_system_with, this method does not require manual registration.
The first time this method is called for a particular system,
it will register the system and store its SystemId in a
CachedSystemId resource for later.
If you would rather manage the SystemId yourself,
or register multiple copies of the same system,
use Commands::register_system instead.
§Limitations
This method only accepts ZST (zero-sized) systems to guarantee that any two systems of the same type must be equal. This means that closures that capture the environment, and function pointers, are not accepted.
If you want to access values from the environment within a system, consider passing them in as inputs.
If that’s not an option, consider Commands::register_system instead.
Sourcepub fn trigger_with<E>(
&mut self,
event: E,
trigger: <E as Event>::Trigger<'static>,
)
pub fn trigger_with<E>( &mut self, event: E, trigger: <E as Event>::Trigger<'static>, )
Sourcepub fn add_observer<E, B, M>(
&mut self,
observer: impl IntoObserverSystem<E, B, M>,
) -> EntityCommands<'_>
pub fn add_observer<E, B, M>( &mut self, observer: impl IntoObserverSystem<E, B, M>, ) -> EntityCommands<'_>
Spawns an Observer and returns the EntityCommands associated
with the entity that stores the observer.
observer can be any system whose first parameter is On.
Calling observe on the returned
EntityCommands will observe the observer itself, which you very
likely do not want.
§Panics
Panics if the given system is an exclusive system.
Sourcepub fn write_message<M>(&mut self, message: M) -> &mut Commands<'w, 's>where
M: Message,
pub fn write_message<M>(&mut self, message: M) -> &mut Commands<'w, 's>where
M: Message,
Writes an arbitrary Message.
This is a convenience method for writing messages
without requiring a MessageWriter.
§Performance
Since this is a command, exclusive world access is used, which means that it will not profit from system-level parallelism on supported platforms.
If these messages are performance-critical or very frequently sent,
consider using a MessageWriter instead.
Sourcepub fn run_schedule(&mut self, label: impl ScheduleLabel)
pub fn run_schedule(&mut self, label: impl ScheduleLabel)
Runs the schedule corresponding to the given ScheduleLabel.
Calls World::try_run_schedule.
§Fallible
This command will fail if the given ScheduleLabel
does not correspond to a Schedule.
It will internally return a TryRunScheduleError,
which will be handled by logging the error at the warn level.
§Example
#[derive(ScheduleLabel, Hash, Debug, PartialEq, Eq, Clone, Copy)]
struct FooSchedule;
commands.run_schedule(FooSchedule);Trait Implementations§
Source§impl CommandsStatesExt for Commands<'_, '_>
impl CommandsStatesExt for Commands<'_, '_>
Source§fn set_state<S>(&mut self, state: S)where
S: FreelyMutableState,
fn set_state<S>(&mut self, state: S)where
S: FreelyMutableState,
Source§fn set_state_if_neq<S>(&mut self, state: S)where
S: FreelyMutableState,
fn set_state_if_neq<S>(&mut self, state: S)where
S: FreelyMutableState,
Source§impl SystemParam for Commands<'_, '_>
impl SystemParam for Commands<'_, '_>
Source§type Item<'w, 's> = Commands<'w, 's>
type Item<'w, 's> = Commands<'w, 's>
Self, instantiated with new lifetimes. Read moreSource§fn init_state(world: &mut World) -> <Commands<'_, '_> as SystemParam>::State
fn init_state(world: &mut World) -> <Commands<'_, '_> as SystemParam>::State
State.Source§fn init_access(
state: &<Commands<'_, '_> as SystemParam>::State,
system_meta: &mut SystemMeta,
component_access_set: &mut FilteredAccessSet,
world: &mut World,
)
fn init_access( state: &<Commands<'_, '_> as SystemParam>::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )
World access used by this SystemParamSource§fn apply(
state: &mut <Commands<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: &mut World,
)
fn apply( state: &mut <Commands<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: &mut World, )
SystemParam’s state.
This is used to apply Commands during ApplyDeferred.Source§fn queue(
state: &mut <Commands<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut <Commands<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
ApplyDeferred.Source§unsafe fn validate_param(
state: &mut <Commands<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'_>,
) -> Result<(), SystemParamValidationError>
unsafe fn validate_param( state: &mut <Commands<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'_>, ) -> Result<(), SystemParamValidationError>
Source§unsafe fn get_param<'w, 's>(
state: &'s mut <Commands<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> <Commands<'_, '_> as SystemParam>::Item<'w, 's>
unsafe fn get_param<'w, 's>( state: &'s mut <Commands<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> <Commands<'_, '_> as SystemParam>::Item<'w, 's>
SystemParamFunction. Read moreimpl<'w, 's> ReadOnlySystemParam for Commands<'w, 's>
impl Send for Commands<'_, '_>
impl Sync for Commands<'_, '_>
Auto Trait Implementations§
impl<'w, 's> Freeze for Commands<'w, 's>
impl<'w, 's> RefUnwindSafe for Commands<'w, 's>
impl<'w, 's> Unpin for Commands<'w, 's>
impl<'w, 's> UnsafeUnpin for Commands<'w, 's>
impl<'w, 's> !UnwindSafe for Commands<'w, 's>
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.