Auto Generated Documentation

This commit is contained in:
github-actions[bot]
2025-04-02 13:41:38 +00:00
parent e9a232e07d
commit 21efed14f2
18523 changed files with 340249 additions and 282417 deletions
@@ -0,0 +1,54 @@
<!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 `PyCapsule`."><title>PyCapsuleMethods 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="#">PyCapsule<wbr>Methods</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.context" title="context">context</a></li><li><a href="#tymethod.is_valid" title="is_valid">is_valid</a></li><li><a href="#tymethod.name" title="name">name</a></li><li><a href="#tymethod.pointer" title="pointer">pointer</a></li><li><a href="#tymethod.reference" title="reference">reference</a></li><li><a href="#tymethod.set_context" title="set_context">set_context</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">PyCapsuleMethods</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/capsule.rs.html#181-248">Source</a> </span></div><pre class="rust item-decl"><code>pub trait PyCapsuleMethods&lt;'py&gt;: Sealed {
// Required methods
fn <a href="#tymethod.set_context" class="fn">set_context</a>(&amp;self, context: <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.pointer.html">*mut </a><a class="type" href="https://doc.rust-lang.org/1.85.1/std/os/raw/type.c_void.html" title="type std::os::raw::c_void">c_void</a>) -&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.context" class="fn">context</a>(&amp;self) -&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.pointer.html">*mut </a><a class="type" href="https://doc.rust-lang.org/1.85.1/std/os/raw/type.c_void.html" title="type std::os::raw::c_void">c_void</a>&gt;;
<span class="item-spacer"></span> unsafe fn <a href="#tymethod.reference" class="fn">reference</a>&lt;T&gt;(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.reference.html">&amp;'py T</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.pointer" class="fn">pointer</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.pointer.html">*mut </a><a class="type" href="https://doc.rust-lang.org/1.85.1/std/os/raw/type.c_void.html" title="type std::os::raw::c_void">c_void</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.is_valid" class="fn">is_valid</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.name" class="fn">name</a>(&amp;self) -&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;&amp;'py <a class="struct" href="https://doc.rust-lang.org/1.85.1/core/ffi/c_str/struct.CStr.html" title="struct core::ffi::c_str::CStr">CStr</a>&gt;&gt;;
}</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.PyCapsule.html" title="struct pyo3::types::PyCapsule"><code>PyCapsule</code></a>.</p>
<p>These methods are defined for the <code>Bound&lt;'py, PyCapsule&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.set_context" class="method"><a class="src rightside" href="../../src/pyo3/types/capsule.rs.html#219">Source</a><h4 class="code-header">fn <a href="#tymethod.set_context" class="fn">set_context</a>(&amp;self, context: <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.pointer.html">*mut </a><a class="type" href="https://doc.rust-lang.org/1.85.1/std/os/raw/type.c_void.html" title="type std::os::raw::c_void">c_void</a>) -&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>Sets the context pointer in the capsule.</p>
<p>Returns an error if this capsule is not valid.</p>
<h5 id="notes"><a class="doc-anchor" href="#notes">§</a>Notes</h5>
<p>The context is treated much like the value of the capsule, but should likely act as
a place to store any state management when using the capsule.</p>
<p>If you want to store a Rust value as the context, and drop it from the destructor, use
<code>Box::into_raw</code> to convert it into a pointer, see the example.</p>
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::os::raw::c_void;
<span class="kw">use </span>std::sync::mpsc::{channel, Sender};
<span class="kw">use </span>pyo3::{prelude::<span class="kw-2">*</span>, types::PyCapsule};
<span class="kw">let </span>(tx, rx) = channel::&lt;String&gt;();
<span class="kw">fn </span>destructor(val: u32, context: <span class="kw-2">*mut </span>c_void) {
<span class="kw">let </span>ctx = <span class="kw">unsafe </span>{ <span class="kw-2">*</span>Box::from_raw(context.cast::&lt;Sender&lt;String&gt;&gt;()) };
ctx.send(<span class="string">"Destructor called!"</span>.to_string()).unwrap();
}
Python::with_gil(|py| {
<span class="kw">let </span>capsule =
PyCapsule::new_with_destructor(py, <span class="number">123</span>, <span class="prelude-val">None</span>, destructor <span class="kw">as fn</span>(u32, <span class="kw-2">*mut </span>c_void))
.unwrap();
<span class="kw">let </span>context = Box::new(tx); <span class="comment">// `Sender&lt;String&gt;` is our context, box it up and ship it!
</span>capsule.set_context(Box::into_raw(context).cast()).unwrap();
<span class="comment">// This scope will end, causing our destructor to be called...
</span>});
<span class="macro">assert_eq!</span>(rx.recv(), <span class="prelude-val">Ok</span>(<span class="string">"Destructor called!"</span>.to_string()));</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.context" class="method"><a class="src rightside" href="../../src/pyo3/types/capsule.rs.html#225">Source</a><h4 class="code-header">fn <a href="#tymethod.context" class="fn">context</a>(&amp;self) -&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.pointer.html">*mut </a><a class="type" href="https://doc.rust-lang.org/1.85.1/std/os/raw/type.c_void.html" title="type std::os::raw::c_void">c_void</a>&gt;</h4></section></summary><div class="docblock"><p>Gets the current context stored in the capsule. If there is no context, the pointer
will be null.</p>
<p>Returns an error if this capsule is not valid.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.reference" class="method"><a class="src rightside" href="../../src/pyo3/types/capsule.rs.html#232">Source</a><h4 class="code-header">unsafe fn <a href="#tymethod.reference" class="fn">reference</a>&lt;T&gt;(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.reference.html">&amp;'py T</a></h4></section></summary><div class="docblock"><p>Obtains a reference to the value of this capsule.</p>
<h5 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h5>
<p>It must be known that this capsule is valid and its pointer is to an item of type <code>T</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.pointer" class="method"><a class="src rightside" href="../../src/pyo3/types/capsule.rs.html#237">Source</a><h4 class="code-header">fn <a href="#tymethod.pointer" class="fn">pointer</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.pointer.html">*mut </a><a class="type" href="https://doc.rust-lang.org/1.85.1/std/os/raw/type.c_void.html" title="type std::os::raw::c_void">c_void</a></h4></section></summary><div class="docblock"><p>Gets the raw <code>c_void</code> pointer to the value in this capsule.</p>
<p>Returns null if this capsule is not valid.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.is_valid" class="method"><a class="src rightside" href="../../src/pyo3/types/capsule.rs.html#242">Source</a><h4 class="code-header">fn <a href="#tymethod.is_valid" class="fn">is_valid</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 this is a valid capsule.</p>
<p>Returns true if the stored <code>pointer()</code> is non-null.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.name" class="method"><a class="src rightside" href="../../src/pyo3/types/capsule.rs.html#247">Source</a><h4 class="code-header">fn <a href="#tymethod.name" class="fn">name</a>(&amp;self) -&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;&amp;'py <a class="struct" href="https://doc.rust-lang.org/1.85.1/core/ffi/c_str/struct.CStr.html" title="struct core::ffi::c_str::CStr">CStr</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Retrieves the name of this capsule, if set.</p>
<p>Returns an error if this capsule is not valid.</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-PyCapsuleMethods%3C'py%3E-for-Bound%3C'py,+PyCapsule%3E" class="impl"><a class="src rightside" href="../../src/pyo3/types/capsule.rs.html#250-302">Source</a><a href="#impl-PyCapsuleMethods%3C'py%3E-for-Bound%3C'py,+PyCapsule%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'py&gt; <a class="trait" href="../types/trait.PyCapsuleMethods.html" title="trait pyo3::types::PyCapsuleMethods">PyCapsuleMethods</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.PyCapsule.html" title="struct pyo3::types::PyCapsule">PyCapsule</a>&gt;</h3></section></div><script src="../../trait.impl/pyo3/types/capsule/trait.PyCapsuleMethods.js" async></script></section></div></main></body></html>