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

36 lines
9.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="Operation to map all contained `Entity` fields in a type to new values."><title>MapEntities in bevy_ecs::entity - 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="#">MapEntities</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.map_entities" title="map_entities">map_entities</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In bevy_<wbr>ecs::<wbr>entity</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">entity</a></span><h1>Trait <span class="trait">MapEntities</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/entity/map_entities.rs.html#47-53">Source</a> </span></div><pre class="rust item-decl"><code>pub trait MapEntities {
// Required method
fn <a href="#tymethod.map_entities" class="fn">map_entities</a>&lt;M: <a class="trait" href="trait.EntityMapper.html" title="trait bevy_ecs::entity::EntityMapper">EntityMapper</a>&gt;(&amp;mut self, entity_mapper: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&amp;mut M</a>);
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Operation to map all contained <a href="struct.Entity.html" title="struct bevy_ecs::entity::Entity"><code>Entity</code></a> fields in a type to new values.</p>
<p>As entity IDs are valid only for the <a href="../world/struct.World.html" title="struct bevy_ecs::world::World"><code>World</code></a> theyre sourced from, using <a href="struct.Entity.html" title="struct bevy_ecs::entity::Entity"><code>Entity</code></a>
as references in components copied from another world will be invalid. This trait
allows defining custom mappings for these references via <a href="trait.EntityMapper.html" title="trait bevy_ecs::entity::EntityMapper"><code>EntityMappers</code></a>, which
inject the entity mapping strategy between your <code>MapEntities</code> type and the current world
(usually by using an <a href="type.EntityHashMap.html" title="type bevy_ecs::entity::EntityHashMap"><code>EntityHashMap&lt;Entity&gt;</code></a> between source entities and entities in the
current world).</p>
<p>This trait is similar to <a href="trait.VisitEntitiesMut.html" title="trait bevy_ecs::entity::VisitEntitiesMut"><code>VisitEntitiesMut</code></a>. They differ in that <a href="trait.VisitEntitiesMut.html" title="trait bevy_ecs::entity::VisitEntitiesMut"><code>VisitEntitiesMut</code></a> operates
on <code>&amp;mut Entity</code> and allows for in-place modification, while this trait makes no assumption that
such in-place modification is occurring, which is impossible for types such as <a href="../../bevy_utils/type.HashSet.html" title="type bevy_utils::HashSet"><code>HashSet&lt;Entity&gt;</code></a>
and <a href="type.EntityHashMap.html" title="type bevy_ecs::entity::EntityHashMap"><code>EntityHashMap</code></a> which must be rebuilt when their contained <a href="struct.Entity.html" title="struct bevy_ecs::entity::Entity"><code>Entity</code></a>s are remapped.</p>
<p>Implementing this trait correctly is required for properly loading components
with entity references from scenes.</p>
<h3 id="example"><a class="doc-anchor" href="#example">§</a>Example</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>bevy_ecs::prelude::<span class="kw-2">*</span>;
<span class="kw">use </span>bevy_ecs::entity::MapEntities;
<span class="attr">#[derive(Component)]
</span><span class="kw">struct </span>Spring {
a: Entity,
b: Entity,
}
<span class="kw">impl </span>MapEntities <span class="kw">for </span>Spring {
<span class="kw">fn </span>map_entities&lt;M: EntityMapper&gt;(<span class="kw-2">&amp;mut </span><span class="self">self</span>, entity_mapper: <span class="kw-2">&amp;mut </span>M) {
<span class="self">self</span>.a = entity_mapper.map_entity(<span class="self">self</span>.a);
<span class="self">self</span>.b = entity_mapper.map_entity(<span class="self">self</span>.b);
}
}</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.map_entities" class="method"><a class="src rightside" href="../../src/bevy_ecs/entity/map_entities.rs.html#52">Source</a><h4 class="code-header">fn <a href="#tymethod.map_entities" class="fn">map_entities</a>&lt;M: <a class="trait" href="trait.EntityMapper.html" title="trait bevy_ecs::entity::EntityMapper">EntityMapper</a>&gt;(&amp;mut self, entity_mapper: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&amp;mut M</a>)</h4></section></summary><div class="docblock"><p>Updates all <a href="struct.Entity.html" title="struct bevy_ecs::entity::Entity"><code>Entity</code></a> references stored inside using <code>entity_mapper</code>.</p>
<p>Implementors should look up any and all <a href="struct.Entity.html" title="struct bevy_ecs::entity::Entity"><code>Entity</code></a> values stored within <code>self</code> and
update them to the mapped values via <code>entity_mapper</code>.</p>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.0/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-MapEntities-for-T" class="impl"><a class="src rightside" href="../../src/bevy_ecs/entity/map_entities.rs.html#55-61">Source</a><a href="#impl-MapEntities-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T: <a class="trait" href="trait.VisitEntitiesMut.html" title="trait bevy_ecs::entity::VisitEntitiesMut">VisitEntitiesMut</a>&gt; <a class="trait" href="trait.MapEntities.html" title="trait bevy_ecs::entity::MapEntities">MapEntities</a> for T</h3></section></div><script src="../../trait.impl/bevy_ecs/entity/map_entities/trait.MapEntities.js" async></script></section></div></main></body></html>