Files
phy/bevy_ecs/system/trait.EntityCommand.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

47 lines
11 KiB
HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A `Command` which gets executed for a given `Entity`."><title>EntityCommand in bevy_ecs::system - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="bevy_ecs" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="icon" href="https://bevyengine.org/assets/icon.png"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../bevy_ecs/index.html"><img src="https://bevyengine.org/assets/icon.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../bevy_ecs/index.html"><img src="https://bevyengine.org/assets/icon.png" alt="logo"></a><h2><a href="../../bevy_ecs/index.html">bevy_<wbr>ecs</a><span class="version">0.15.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Entity<wbr>Command</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.apply" title="apply">apply</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.with_entity" title="with_entity">with_entity</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In bevy_<wbr>ecs::<wbr>system</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">bevy_ecs</a>::<wbr><a href="index.html">system</a></span><h1>Trait <span class="trait">EntityCommand</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/bevy_ecs/system/commands/mod.rs.html#1031-1048">Source</a> </span></div><pre class="rust item-decl"><code>pub trait EntityCommand&lt;Marker = <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.unit.html">()</a>&gt;: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static {
// Required method
fn <a href="#tymethod.apply" class="fn">apply</a>(self, entity: <a class="struct" href="../entity/struct.Entity.html" title="struct bevy_ecs::entity::Entity">Entity</a>, world: &amp;mut <a class="struct" href="../world/struct.World.html" title="struct bevy_ecs::world::World">World</a>);
// Provided method
fn <a href="#method.with_entity" class="fn">with_entity</a>(self, entity: <a class="struct" href="../entity/struct.Entity.html" title="struct bevy_ecs::entity::Entity">Entity</a>) -&gt; impl <a class="trait" href="../world/trait.Command.html" title="trait bevy_ecs::world::Command">Command</a>
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A <a href="../world/trait.Command.html" title="trait bevy_ecs::world::Command"><code>Command</code></a> which gets executed for a given <a href="../entity/struct.Entity.html" title="struct bevy_ecs::entity::Entity"><code>Entity</code></a>.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>bevy_ecs::system::EntityCommand;
<span class="attr">#[derive(Resource, Default)]
</span><span class="kw">struct </span>Counter(i64);
<span class="doccomment">/// A `Command` which names an entity based on a global counter.
</span><span class="kw">fn </span>count_name(entity: Entity, world: <span class="kw-2">&amp;mut </span>World) {
<span class="comment">// Get the current value of the counter, and increment it for next time.
</span><span class="kw">let </span><span class="kw-2">mut </span>counter = world.resource_mut::&lt;Counter&gt;();
<span class="kw">let </span>i = counter.<span class="number">0</span>;
counter.<span class="number">0 </span>+= <span class="number">1</span>;
<span class="comment">// Name the entity after the value of the counter.
</span>world.entity_mut(entity).insert(Name::new(<span class="macro">format!</span>(<span class="string">"Entity #{i}"</span>)));
}
<span class="comment">// App creation boilerplate omitted...
</span><span class="kw">fn </span>setup(<span class="kw-2">mut </span>commands: Commands) {
commands.spawn_empty().queue(count_name);
commands.spawn_empty().queue(count_name);
}
<span class="kw">fn </span>assert_names(named: Query&lt;<span class="kw-2">&amp;</span>Name&gt;) {
<span class="comment">// We use a HashSet because we do not care about the order.
</span><span class="kw">let </span>names: HashSet&lt;<span class="kw">_</span>&gt; = named.iter().map(Name::as_str).collect();
<span class="macro">assert_eq!</span>(names, HashSet::from_iter([<span class="string">"Entity #0"</span>, <span class="string">"Entity #1"</span>]));
}</code></pre></div>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.apply" class="method"><a class="src rightside" href="../../src/bevy_ecs/system/commands/mod.rs.html#1033">Source</a><h4 class="code-header">fn <a href="#tymethod.apply" class="fn">apply</a>(self, entity: <a class="struct" href="../entity/struct.Entity.html" title="struct bevy_ecs::entity::Entity">Entity</a>, world: &amp;mut <a class="struct" href="../world/struct.World.html" title="struct bevy_ecs::world::World">World</a>)</h4></section></summary><div class="docblock"><p>Executes this command for the given <a href="../entity/struct.Entity.html" title="struct bevy_ecs::entity::Entity"><code>Entity</code></a>.</p>
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.with_entity" class="method"><a class="src rightside" href="../../src/bevy_ecs/system/commands/mod.rs.html#1042-1047">Source</a><h4 class="code-header">fn <a href="#method.with_entity" class="fn">with_entity</a>(self, entity: <a class="struct" href="../entity/struct.Entity.html" title="struct bevy_ecs::entity::Entity">Entity</a>) -&gt; impl <a class="trait" href="../world/trait.Command.html" title="trait bevy_ecs::world::Command">Command</a><div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Returns a <a href="../world/trait.Command.html" title="trait bevy_ecs::world::Command"><code>Command</code></a> which executes this <a href="trait.EntityCommand.html" title="trait bevy_ecs::system::EntityCommand"><code>EntityCommand</code></a> for the given <a href="../entity/struct.Entity.html" title="struct bevy_ecs::entity::Entity"><code>Entity</code></a>.</p>
<p>This method is called when adding an <a href="trait.EntityCommand.html" title="trait bevy_ecs::system::EntityCommand"><code>EntityCommand</code></a> to a command queue via <a href="struct.Commands.html" title="struct bevy_ecs::system::Commands"><code>Commands</code></a>.
You can override the provided implementation if you can return a <code>Command</code> with a smaller memory
footprint than <code>(Entity, Self)</code>.
In most cases the provided implementation is sufficient.</p>
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-EntityCommand-for-F" class="impl"><a class="src rightside" href="../../src/bevy_ecs/system/commands/mod.rs.html#1794-1801">Source</a><a href="#impl-EntityCommand-for-F" class="anchor">§</a><h3 class="code-header">impl&lt;F&gt; <a class="trait" href="trait.EntityCommand.html" title="trait bevy_ecs::system::EntityCommand">EntityCommand</a> for F<div class="where">where
F: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="struct" href="../entity/struct.Entity.html" title="struct bevy_ecs::entity::Entity">Entity</a>, &amp;mut <a class="struct" href="../world/struct.World.html" title="struct bevy_ecs::world::World">World</a>) + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,</div></h3></section><section id="impl-EntityCommand%3CWorld%3E-for-F" class="impl"><a class="src rightside" href="../../src/bevy_ecs/system/commands/mod.rs.html#1785-1792">Source</a><a href="#impl-EntityCommand%3CWorld%3E-for-F" class="anchor">§</a><h3 class="code-header">impl&lt;F&gt; <a class="trait" href="trait.EntityCommand.html" title="trait bevy_ecs::system::EntityCommand">EntityCommand</a>&lt;<a class="struct" href="../world/struct.World.html" title="struct bevy_ecs::world::World">World</a>&gt; for F<div class="where">where
F: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(<a class="struct" href="../world/struct.EntityWorldMut.html" title="struct bevy_ecs::world::EntityWorldMut">EntityWorldMut</a>&lt;'_&gt;) + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,</div></h3></section></div><script src="../../trait.impl/bevy_ecs/system/commands/trait.EntityCommand.js" async></script></section></div></main></body></html>