rust-analyzer/stdx/anymap/trait.Downcast.html
github-merge-queue[bot] 0ea917a364 deploy: d048a477dc
2025-09-10 02:41:40 +00:00

16 lines
No EOL
14 KiB
HTML
Raw Permalink 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="Methods for downcasting from an `Any`-like trait object."><title>Downcast in stdx::anymap - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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-84e720fa.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="stdx" data-themes="" data-resource-suffix="" data-rustdoc-version="1.89.0 (29483883e 2025-08-04)" data-channel="1.89.0" data-search-js="search-92309212.js" data-settings-js="settings-5514c975.js" ><script src="../../static.files/storage-4e99c027.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-fd3af306.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></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></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../stdx/index.html">stdx</a><span class="version">0.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Downcast</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.downcast_mut_unchecked" title="downcast_mut_unchecked">downcast_mut_unchecked</a></li><li><a href="#tymethod.downcast_ref_unchecked" title="downcast_ref_unchecked">downcast_ref_unchecked</a></li><li><a href="#tymethod.type_id" title="type_id">type_id</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Downcast-for-dyn+Any" title="dyn Any">dyn Any</a></li><li><a href="#impl-Downcast-for-dyn+Any+%2B+Send" title="dyn Any + Send">dyn Any + Send</a></li><li><a href="#impl-Downcast-for-dyn+Any+%2B+Send+%2B+Sync" title="dyn Any + Send + Sync">dyn Any + Send + Sync</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 stdx::<wbr>anymap</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">stdx</a>::<wbr><a href="index.html">anymap</a></div><h1>Trait <span class="trait">Downcast</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/stdx/anymap.rs.html#227-255">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Downcast {
// Required methods
fn <a href="#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.89.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a>;
<span class="item-spacer"></span> unsafe fn <a href="#tymethod.downcast_ref_unchecked" class="fn">downcast_ref_unchecked</a>&lt;T: 'static&gt;(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;T</a>;
<span class="item-spacer"></span> unsafe fn <a href="#tymethod.downcast_mut_unchecked" class="fn">downcast_mut_unchecked</a>&lt;T: 'static&gt;(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;mut T</a>;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Methods for downcasting from an <code>Any</code>-like trait object.</p>
<p>This should only be implemented on trait objects for subtraits of <code>Any</code>, though you can
implement it for other types and itll work fine, so long as your implementation is correct.</p>
</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.type_id" class="method"><a class="src rightside" href="../../src/stdx/anymap.rs.html#229">Source</a><h4 class="code-header">fn <a href="#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.89.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class="docblock"><p>Gets the <code>TypeId</code> of <code>self</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.downcast_ref_unchecked" class="method"><a class="src rightside" href="../../src/stdx/anymap.rs.html#247">Source</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_ref_unchecked" class="fn">downcast_ref_unchecked</a>&lt;T: 'static&gt;(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;T</a></h4></section></summary><div class="docblock"><p>Downcast from <code>&amp;Any</code> to <code>&amp;T</code>, without checking the type matches.</p>
<h5 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h5>
<p>The caller must ensure that <code>T</code> matches the trait object, on pain of <em>undefined behavior</em>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.downcast_mut_unchecked" class="method"><a class="src rightside" href="../../src/stdx/anymap.rs.html#254">Source</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_mut_unchecked" class="fn">downcast_mut_unchecked</a>&lt;T: 'static&gt;(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;mut T</a></h4></section></summary><div class="docblock"><p>Downcast from <code>&amp;mut Any</code> to <code>&amp;mut T</code>, without checking the type matches.</p>
<h5 id="safety-1"><a class="doc-anchor" href="#safety-1">§</a>Safety</h5>
<p>The caller must ensure that <code>T</code> matches the trait object, on pain of <em>undefined behavior</em>.</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.89.0/reference/items/traits.html#dyn-compatibility">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="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-Downcast-for-dyn+Any" class="impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#291">Source</a><a href="#impl-Downcast-for-dyn+Any" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Downcast.html" title="trait stdx::anymap::Downcast">Downcast</a> for dyn <a class="trait" href="https://doc.rust-lang.org/1.89.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a></h3></section></summary><div class="impl-items"><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#291">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.89.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section><section id="method.downcast_ref_unchecked" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#291">Source</a><a href="#method.downcast_ref_unchecked" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_ref_unchecked" class="fn">downcast_ref_unchecked</a>&lt;T: 'static&gt;(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;T</a></h4></section><section id="method.downcast_mut_unchecked" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#291">Source</a><a href="#method.downcast_mut_unchecked" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_mut_unchecked" class="fn">downcast_mut_unchecked</a>&lt;T: 'static&gt;(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;mut T</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Downcast-for-dyn+Any+%2B+Send" class="impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#292">Source</a><a href="#impl-Downcast-for-dyn+Any+%2B+Send" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Downcast.html" title="trait stdx::anymap::Downcast">Downcast</a> for dyn <a class="trait" href="https://doc.rust-lang.org/1.89.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> + <a class="trait" href="https://doc.rust-lang.org/1.89.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></h3></section></summary><div class="impl-items"><section id="method.type_id-1" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#292">Source</a><a href="#method.type_id-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.89.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section><section id="method.downcast_ref_unchecked-1" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#292">Source</a><a href="#method.downcast_ref_unchecked-1" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_ref_unchecked" class="fn">downcast_ref_unchecked</a>&lt;T: 'static&gt;(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;T</a></h4></section><section id="method.downcast_mut_unchecked-1" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#292">Source</a><a href="#method.downcast_mut_unchecked-1" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_mut_unchecked" class="fn">downcast_mut_unchecked</a>&lt;T: 'static&gt;(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;mut T</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Downcast-for-dyn+Any+%2B+Send+%2B+Sync" class="impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#293">Source</a><a href="#impl-Downcast-for-dyn+Any+%2B+Send+%2B+Sync" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Downcast.html" title="trait stdx::anymap::Downcast">Downcast</a> for dyn <a class="trait" href="https://doc.rust-lang.org/1.89.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> + <a class="trait" href="https://doc.rust-lang.org/1.89.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.89.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a></h3></section></summary><div class="impl-items"><section id="method.type_id-2" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#293">Source</a><a href="#method.type_id-2" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.89.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section><section id="method.downcast_ref_unchecked-2" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#293">Source</a><a href="#method.downcast_ref_unchecked-2" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_ref_unchecked" class="fn">downcast_ref_unchecked</a>&lt;T: 'static&gt;(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;T</a></h4></section><section id="method.downcast_mut_unchecked-2" class="method trait-impl"><a class="src rightside" href="../../src/stdx/anymap.rs.html#293">Source</a><a href="#method.downcast_mut_unchecked-2" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="#tymethod.downcast_mut_unchecked" class="fn">downcast_mut_unchecked</a>&lt;T: 'static&gt;(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.89.0/std/primitive.reference.html">&amp;mut T</a></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../../trait.impl/stdx/anymap/trait.Downcast.js" data-ignore-extern-crates="core" async></script></section></div></main></body></html>