82 lines
29 KiB
HTML
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<'py>: 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>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>>>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.clear" class="fn">clear</a>(&self);
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.len" class="fn">len</a>(&self) -> <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>(&self) -> <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><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>>
|
|
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.get_item" class="fn">get_item</a><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>>
|
|
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.set_item" class="fn">set_item</a><K, V>(&self, key: K, value: V) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>
|
|
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,
|
|
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.del_item" class="fn">del_item</a><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>
|
|
<span class="where">where K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py></span>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.keys" class="fn">keys</a>(&self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.values" class="fn">values</a>(&self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.items" class="fn">items</a>(&self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.iter" class="fn">iter</a>(&self) -> <a class="struct" href="../types/iter/struct.BoundDictIterator.html" title="struct pyo3::types::iter::BoundDictIterator">BoundDictIterator</a><'py> <a href="#" class="tooltip" data-notable-ty="BoundDictIterator<'py>">ⓘ</a>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.locked_for_each" class="fn">locked_for_each</a><F>(&self, closure: F) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>
|
|
<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><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>, <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>></span>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.as_mapping" class="fn">as_mapping</a>(&self) -> &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.into_mapping" class="fn">into_mapping</a>(self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.update" class="fn">update</a>(&self, other: &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'_, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>>) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.update_if_missing" class="fn">update_if_missing</a>(&self, other: &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'_, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>>) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>;
|
|
</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<'py, PyDict></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>(&self) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>>></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>(&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>(&self) -> <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>(&self) -> <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><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.bool.html">bool</a>><div class="where">where
|
|
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</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><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="enum" href="https://doc.rust-lang.org/1.85.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>>><div class="where">where
|
|
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</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><K, V>(&self, key: K, value: V) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>><div class="where">where
|
|
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,
|
|
V: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</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><K>(&self, key: K) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>><div class="where">where
|
|
K: <a class="trait" href="../conversion/trait.IntoPyObject.html" title="trait pyo3::conversion::IntoPyObject">IntoPyObject</a><'py>,</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>(&self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>></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>(&self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>></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>(&self) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyList.html" title="struct pyo3::types::PyList">PyList</a>></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>(&self) -> <a class="struct" href="../types/iter/struct.BoundDictIterator.html" title="struct pyo3::types::iter::BoundDictIterator">BoundDictIterator</a><'py> <a href="#" class="tooltip" data-notable-ty="BoundDictIterator<'py>">ⓘ</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><F>(&self, closure: F) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>><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><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>, <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyAny.html" title="struct pyo3::types::PyAny">PyAny</a>>) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>>,</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>(&self) -> &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>></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) -> <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>></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>(&self, other: &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'_, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>>) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>></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>(&self, other: &<a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'_, <a class="struct" href="../types/struct.PyMapping.html" title="struct pyo3::types::PyMapping">PyMapping</a>>) -> <a class="type" href="../type.PyResult.html" title="type pyo3::PyResult">PyResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.unit.html">()</a>></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<'py> <a class="trait" href="../types/trait.PyDictMethods.html" title="trait pyo3::types::PyDictMethods">PyDictMethods</a><'py> for <a class="struct" href="../struct.Bound.html" title="struct pyo3::Bound">Bound</a><'py, <a class="struct" href="../types/struct.PyDict.html" title="struct pyo3::types::PyDict">PyDict</a>></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><'py></code></h3><pre><code><div class=\"where\">impl<'py> <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><'py></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><'py, <a class=\"struct\" href=\"../types/struct.PyAny.html\" title=\"struct pyo3::types::PyAny\">PyAny</a>>, <a class=\"struct\" href=\"../struct.Bound.html\" title=\"struct pyo3::Bound\">Bound</a><'py, <a class=\"struct\" href=\"../types/struct.PyAny.html\" title=\"struct pyo3::types::PyAny\">PyAny</a>>);</div>"}</script></section></div></main></body></html> |