Files
google_speech_rs/docs/pyo3/prelude/trait.PyDictMethods.html
2025-04-02 13:41:38 +00:00

82 lines
29 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="Implementation of functionality for `PyDict`."><title>PyDictMethods in pyo3::prelude - 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-46132b98.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="pyo3" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.1 (4eb161250 2025-03-15)" data-channel="1.85.1" data-search-js="search-75f5ac3e.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="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="../../pyo3/index.html">pyo3</a><span class="version">0.24.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">PyDict<wbr>Methods</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.as_mapping" title="as_mapping">as_mapping</a></li><li><a href="#tymethod.clear" title="clear">clear</a></li><li><a href="#tymethod.contains" title="contains">contains</a></li><li><a href="#tymethod.copy" title="copy">copy</a></li><li><a href="#tymethod.del_item" title="del_item">del_item</a></li><li><a href="#tymethod.get_item" title="get_item">get_item</a></li><li><a href="#tymethod.into_mapping" title="into_mapping">into_mapping</a></li><li><a href="#tymethod.is_empty" title="is_empty">is_empty</a></li><li><a href="#tymethod.items" title="items">items</a></li><li><a href="#tymethod.iter" title="iter">iter</a></li><li><a href="#tymethod.keys" title="keys">keys</a></li><li><a href="#tymethod.len" title="len">len</a></li><li><a href="#tymethod.locked_for_each" title="locked_for_each">locked_for_each</a></li><li><a href="#tymethod.set_item" title="set_item">set_item</a></li><li><a href="#tymethod.update" title="update">update</a></li><li><a href="#tymethod.update_if_missing" title="update_if_missing">update_if_missing</a></li><li><a href="#tymethod.values" title="values">values</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 pyo3::<wbr>prelude</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">pyo3</a>::<wbr><a href="index.html">prelude</a></span><h1>Trait <span class="trait">PyDictMethods</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/pyo3/types/dict.rs.html#109-216">Source</a> </span></div><pre class="rust item-decl"><code>pub trait PyDictMethods&lt;'py&gt;: Sealed {
<details class="toggle type-contents-toggle"><summary class="hideme"><span>Show 17 methods</span></summary> // Required methods
fn <a href="#tymethod.copy" class="fn">copy</a>(&amp;self) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>&gt;&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;self);
<span class="item-spacer"></span> fn <a href="#tymethod.len" class="fn">len</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.usize.html">usize</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.is_empty" class="fn">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.contains" class="fn">contains</a>&lt;K&gt;(&amp;self, key: K) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>&gt;
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.get_item" class="fn">get_item</a>&lt;K&gt;(&amp;self, key: K) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>&gt;&gt;&gt;
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.set_item" class="fn">set_item</a>&lt;K, V&gt;(&amp;self, key: K, value: V) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;,
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.del_item" class="fn">del_item</a>&lt;K&gt;(&amp;self, key: K) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.keys" class="fn">keys</a>(&amp;self) -&gt; <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.values" class="fn">values</a>(&amp;self) -&gt; <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.items" class="fn">items</a>(&amp;self) -&gt; <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.iter" class="fn">iter</a>(&amp;self) -&gt; <a class="struct" href="../types/iter/struct.BoundDictIterator.html" title="struct pyo3::types::iter::BoundDictIterator">BoundDictIterator</a>&lt;'py&gt; <a href="#" class="tooltip" data-notable-ty="BoundDictIterator&lt;&#39;py&gt;"></a>;
<span class="item-spacer"></span> fn <a href="#tymethod.locked_for_each" class="fn">locked_for_each</a>&lt;F&gt;(&amp;self, closure: F) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;
<span class="where">where F: <a class="trait" href="https://doc.rust-lang.org/1.85.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>&gt;, <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>&gt;) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;</span>;
<span class="item-spacer"></span> fn <a href="#tymethod.as_mapping" class="fn">as_mapping</a>(&amp;self) -&gt; &amp;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.into_mapping" class="fn">into_mapping</a>(self) -&gt; <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.update" class="fn">update</a>(&amp;self, other: &amp;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'_, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>&gt;) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.update_if_missing" class="fn">update_if_missing</a>(&amp;self, other: &amp;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'_, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>&gt;) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;;
</details>}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Implementation of functionality for <a href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict"><code>PyDict</code></a>.</p>
<p>These methods are defined for the <code>Bound&lt;'py, PyDict&gt;</code> smart pointer, so to use method call
syntax these methods are separated into a trait, because stable Rust does not yet support
<code>arbitrary_self_types</code>.</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.copy" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#113">Source</a><h4 class="code-header">fn <a href="#tymethod.copy" class="fn">copy</a>(&amp;self) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Returns a new dictionary that contains the same key-value pairs as self.</p>
<p>This is equivalent to the Python expression <code>self.copy()</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.clear" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#116">Source</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;self)</h4></section></summary><div class="docblock"><p>Empties an existing dictionary of all key-value pairs.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.len" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#121">Source</a><h4 class="code-header">fn <a href="#tymethod.len" class="fn">len</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Return the number of items in the dictionary.</p>
<p>This is equivalent to the Python expression <code>len(self)</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_empty" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#124">Source</a><h4 class="code-header">fn <a href="#tymethod.is_empty" class="fn">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Checks if the dict is empty, i.e. <code>len(self) == 0</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.contains" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#129-131">Source</a><h4 class="code-header">fn <a href="#tymethod.contains" class="fn">contains</a>&lt;K&gt;(&amp;self, key: K) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>&gt;<div class="where">where
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;,</div></h4></section></summary><div class="docblock"><p>Determines if the dictionary contains the specified key.</p>
<p>This is equivalent to the Python expression <code>key in self</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.get_item" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#138-140">Source</a><h4 class="code-header">fn <a href="#tymethod.get_item" class="fn">get_item</a>&lt;K&gt;(&amp;self, key: K) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>&gt;&gt;&gt;<div class="where">where
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;,</div></h4></section></summary><div class="docblock"><p>Gets an item from the dictionary.</p>
<p>Returns <code>None</code> if the item is not present, or if an error occurs.</p>
<p>To get a <code>KeyError</code> for non-existing keys, use <code>PyAny::get_item</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.set_item" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#145-148">Source</a><h4 class="code-header">fn <a href="#tymethod.set_item" class="fn">set_item</a>&lt;K, V&gt;(&amp;self, key: K, value: V) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;<div class="where">where
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;,
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;,</div></h4></section></summary><div class="docblock"><p>Sets an item value.</p>
<p>This is equivalent to the Python statement <code>self[key] = value</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.del_item" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#153-155">Source</a><h4 class="code-header">fn <a href="#tymethod.del_item" class="fn">del_item</a>&lt;K&gt;(&amp;self, key: K) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;<div class="where">where
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a>&lt;'py&gt;,</div></h4></section></summary><div class="docblock"><p>Deletes an item.</p>
<p>This is equivalent to the Python statement <code>del self[key]</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.keys" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#160">Source</a><h4 class="code-header">fn <a href="#tymethod.keys" class="fn">keys</a>(&amp;self) -&gt; <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>&gt;</h4></section></summary><div class="docblock"><p>Returns a list of dict keys.</p>
<p>This is equivalent to the Python expression <code>list(dict.keys())</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.values" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#165">Source</a><h4 class="code-header">fn <a href="#tymethod.values" class="fn">values</a>(&amp;self) -&gt; <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>&gt;</h4></section></summary><div class="docblock"><p>Returns a list of dict values.</p>
<p>This is equivalent to the Python expression <code>list(dict.values())</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.items" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#170">Source</a><h4 class="code-header">fn <a href="#tymethod.items" class="fn">items</a>(&amp;self) -&gt; <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>&gt;</h4></section></summary><div class="docblock"><p>Returns a list of dict items.</p>
<p>This is equivalent to the Python expression <code>list(dict.items())</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.iter" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#179">Source</a><h4 class="code-header">fn <a href="#tymethod.iter" class="fn">iter</a>(&amp;self) -&gt; <a class="struct" href="../types/iter/struct.BoundDictIterator.html" title="struct pyo3::types::iter::BoundDictIterator">BoundDictIterator</a>&lt;'py&gt; <a href="#" class="tooltip" data-notable-ty="BoundDictIterator&lt;&#39;py&gt;"></a></h4></section></summary><div class="docblock"><p>Returns an iterator of <code>(key, value)</code> pairs in this dictionary.</p>
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
<p>If PyO3 detects that the dictionary is mutated during iteration, it will panic.
It is allowed to modify values as you iterate over the dictionary, but only
so long as the set of keys does not change.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.locked_for_each" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#191-193">Source</a><h4 class="code-header">fn <a href="#tymethod.locked_for_each" class="fn">locked_for_each</a>&lt;F&gt;(&amp;self, closure: F) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;<div class="where">where
F: <a class="trait" href="https://doc.rust-lang.org/1.85.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>&gt;, <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>&gt;) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;,</div></h4></section></summary><div class="docblock"><p>Iterates over the contents of this dictionary while holding a critical section on the dict.
This is useful when the GIL is disabled and the dictionary is shared between threads.
It is not guaranteed that the dictionary will not be modified during iteration when the
closure calls arbitrary Python code that releases the critical section held by the
iterator. Otherwise, the dictionary will not be modified during iteration.</p>
<p>This method is a small performance optimization over <code>.iter().try_for_each()</code> when the
nightly feature is not enabled because we cannot implement an optimised version of
<code>iter().try_fold()</code> on stable yet. If your iteration is infallible then this method has the
same performance as <code>.iter().for_each()</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.as_mapping" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#196">Source</a><h4 class="code-header">fn <a href="#tymethod.as_mapping" class="fn">as_mapping</a>(&amp;self) -&gt; &amp;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>&gt;</h4></section></summary><div class="docblock"><p>Returns <code>self</code> cast as a <code>PyMapping</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.into_mapping" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#199">Source</a><h4 class="code-header">fn <a href="#tymethod.into_mapping" class="fn">into_mapping</a>(self) -&gt; <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>&gt;</h4></section></summary><div class="docblock"><p>Returns <code>self</code> cast as a <code>PyMapping</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.update" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#205">Source</a><h4 class="code-header">fn <a href="#tymethod.update" class="fn">update</a>(&amp;self, other: &amp;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'_, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>&gt;) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Update this dictionary with the key/value pairs from another.</p>
<p>This is equivalent to the Python expression <code>self.update(other)</code>. If <code>other</code> is a <code>PyDict</code>, you may want
to use <code>self.update(other.as_mapping())</code>, note: <code>PyDict::as_mapping</code> is a zero-cost conversion.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.update_if_missing" class="method"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#215">Source</a><h4 class="code-header">fn <a href="#tymethod.update_if_missing" class="fn">update_if_missing</a>(&amp;self, other: &amp;<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'_, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>&gt;) -&gt; <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>&gt;</h4></section></summary><div class="docblock"><p>Add key/value pairs from another dictionary to this one only when they do not exist in this.</p>
<p>This is equivalent to the Python expression <code>self.update({k: v for k, v in other.items() if k not in self})</code>.
If <code>other</code> is a <code>PyDict</code>, you may want to use <code>self.update_if_missing(other.as_mapping())</code>,
note: <code>PyDict::as_mapping</code> is a zero-cost conversion.</p>
<p>This method uses <a href="https://docs.python.org/3/c-api/dict.html#c.PyDict_Merge"><code>PyDict_Merge</code></a> internally,
so should have the same performance as <code>update</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.85.1/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-PyDictMethods%3C'py%3E-for-Bound%3C'py,+PyDict%3E" class="impl"><a class="src rightside" href="../../src/pyo3/types/dict.rs.html#218-394">Source</a><a href="#impl-PyDictMethods%3C'py%3E-for-Bound%3C'py,+PyDict%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'py&gt; <a class="trait" href="../types/trait.PyDictMethods.html" title="trait pyo3::types::PyDictMethods">PyDictMethods</a>&lt;'py&gt; for <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a>&lt;'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>&gt;</h3></section></div><script src="../../trait.impl/pyo3/types/dict/trait.PyDictMethods.js" async></script><script type="text/json" id="notable-traits-data">{"BoundDictIterator<'py>":"<h3>Notable traits for <code><a class=\"struct\" href=\"../types/iter/struct.BoundDictIterator.html\" title=\"struct pyo3::types::iter::BoundDictIterator\">BoundDictIterator</a>&lt;'py&gt;</code></h3><pre><code><div class=\"where\">impl&lt;'py&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.85.1/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"../types/iter/struct.BoundDictIterator.html\" title=\"struct pyo3::types::iter::BoundDictIterator\">BoundDictIterator</a>&lt;'py&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.85.1/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = (<a class=\"struct\" href=\"../struct.Bound.html\" title=\"struct pyo3::Bound\">Bound</a>&lt;'py, <a class=\"struct\" href=\"../types/struct.PyAny.html\" title=\"struct pyo3::types::PyAny\">PyAny</a>&gt;, <a class=\"struct\" href=\"../struct.Bound.html\" title=\"struct pyo3::Bound\">Bound</a>&lt;'py, <a class=\"struct\" href=\"../types/struct.PyAny.html\" title=\"struct pyo3::types::PyAny\">PyAny</a>&gt;);</div>"}</script></section></div></main></body></html>