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

30 lines
14 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="Expected form of `FromPyObject` to be used in a future PyO3 release."><title>FromPyObjectBound in pyo3::conversion - 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="#">From<wbr>PyObject<wbr>Bound</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#usage" title="Usage">Usage</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.from_py_object_bound" title="from_py_object_bound">from_py_object_bound</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-FromPyObjectBound%3C'a,+'_%3E-for-%26%5Bu8%5D" title="&#38;&#39;a [u8]">&#38;&#39;a [u8]</a></li><li><a href="#impl-FromPyObjectBound%3C'a,+'_%3E-for-%26str" title="&#38;&#39;a str">&#38;&#39;a str</a></li><li><a href="#impl-FromPyObjectBound%3C'a,+'_%3E-for-Cow%3C'a,+%5Bu8%5D%3E" title="Cow&#60;&#39;a, [u8]&#62;">Cow&#60;&#39;a, [u8]&#62;</a></li><li><a href="#impl-FromPyObjectBound%3C'a,+'_%3E-for-Cow%3C'a,+str%3E" title="Cow&#60;&#39;a, str&#62;">Cow&#60;&#39;a, str&#62;</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>conversion</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">conversion</a></span><h1>Trait <span class="trait">FromPyObjectBound</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/conversion.rs.html#509-528">Source</a> </span></div><pre class="rust item-decl"><code>pub trait FromPyObjectBound&lt;'a, 'py&gt;: <a class="trait" href="https://doc.rust-lang.org/1.85.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + Sealed {
// Required method
fn <a href="#tymethod.from_py_object_bound" class="fn">from_py_object_bound</a>(ob: <a class="struct" href="../struct.Borrowed.html" title="struct pyo3::Borrowed">Borrowed</a>&lt;'a, '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;Self&gt;;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Expected form of <a href="trait.FromPyObject.html" title="trait pyo3::conversion::FromPyObject"><code>FromPyObject</code></a> to be used in a future PyO3 release.</p>
<p>The difference between this and <code>FromPyObject</code> is that this trait takes an
additional lifetime <code>'a</code>, which is the lifetime of the input <code>Bound</code>.</p>
<p>This allows implementations for <code>&amp;'a str</code> and <code>&amp;'a [u8]</code>, which could not
be expressed by the existing <code>FromPyObject</code> trait once the GIL Refs API was
removed.</p>
<h2 id="usage"><a class="doc-anchor" href="#usage">§</a>Usage</h2>
<p>Users are prevented from implementing this trait, instead they should implement
the normal <code>FromPyObject</code> trait. This trait has a blanket implementation
for <code>T: FromPyObject</code>.</p>
<p>The only case where this trait may have a use case to be implemented is when the
lifetime of the extracted value is tied to the lifetime <code>'a</code> of the input <code>Bound</code>
instead of the GIL lifetime <code>py</code>, as is the case for the <code>&amp;'a str</code> implementation.</p>
<p>Please contact the PyO3 maintainers if you believe you have a use case for implementing
this trait before PyO3 is ready to change the main <code>FromPyObject</code> trait to take an
additional lifetime.</p>
<p>Similarly, users should typically not call these trait methods and should instead
use this via the <code>extract</code> method on <code>Bound</code> and <code>Py</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.from_py_object_bound" class="method"><a class="src rightside" href="../../src/pyo3/conversion.rs.html#514">Source</a><h4 class="code-header">fn <a href="#tymethod.from_py_object_bound" class="fn">from_py_object_bound</a>(ob: <a class="struct" href="../struct.Borrowed.html" title="struct pyo3::Borrowed">Borrowed</a>&lt;'a, '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;Self&gt;</h4></section></summary><div class="docblock"><p>Extracts <code>Self</code> from the bound smart pointer <code>obj</code>.</p>
<p>Users are advised against calling this method directly: instead, use this via
[<code>Bound&lt;'_, PyAny&gt;::extract</code>] or <a href="../struct.Py.html#method.extract" title="method pyo3::Py::extract"><code>Py::extract</code></a>.</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="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-FromPyObjectBound%3C'a,+'_%3E-for-%26str" class="impl"><a class="src rightside" href="../../src/pyo3/conversions/std/string.rs.html#228-237">Source</a><a href="#impl-FromPyObjectBound%3C'a,+'_%3E-for-%26str" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.FromPyObjectBound.html" title="trait pyo3::conversion::FromPyObjectBound">FromPyObjectBound</a>&lt;'a, '_&gt; for &amp;'a <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.str.html">str</a></h3></section></summary><div class="impl-items"><section id="method.from_py_object_bound" class="method trait-impl"><a class="src rightside" href="../../src/pyo3/conversions/std/string.rs.html#229-231">Source</a><a href="#method.from_py_object_bound" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.from_py_object_bound" class="fn">from_py_object_bound</a>(ob: <a class="struct" href="../struct.Borrowed.html" title="struct pyo3::Borrowed">Borrowed</a>&lt;'a, '_, <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;Self&gt;</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-FromPyObjectBound%3C'a,+'_%3E-for-%26%5Bu8%5D" class="impl"><a class="src rightside" href="../../src/pyo3/conversions/std/slice.rs.html#47-56">Source</a><a href="#impl-FromPyObjectBound%3C'a,+'_%3E-for-%26%5Bu8%5D" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.FromPyObjectBound.html" title="trait pyo3::conversion::FromPyObjectBound">FromPyObjectBound</a>&lt;'a, '_&gt; for &amp;'a [<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.u8.html">u8</a>]</h3></section></summary><div class="impl-items"><section id="method.from_py_object_bound-1" class="method trait-impl"><a class="src rightside" href="../../src/pyo3/conversions/std/slice.rs.html#48-50">Source</a><a href="#method.from_py_object_bound-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.from_py_object_bound" class="fn">from_py_object_bound</a>(obj: <a class="struct" href="../struct.Borrowed.html" title="struct pyo3::Borrowed">Borrowed</a>&lt;'a, '_, <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;Self&gt;</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-FromPyObjectBound%3C'a,+'_%3E-for-Cow%3C'a,+str%3E" class="impl"><a class="src rightside" href="../../src/pyo3/conversions/std/string.rs.html#239-248">Source</a><a href="#impl-FromPyObjectBound%3C'a,+'_%3E-for-Cow%3C'a,+str%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.FromPyObjectBound.html" title="trait pyo3::conversion::FromPyObjectBound">FromPyObjectBound</a>&lt;'a, '_&gt; for <a class="enum" href="https://doc.rust-lang.org/1.85.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;'a, <a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.str.html">str</a>&gt;</h3></section></summary><div class="impl-items"><section id="method.from_py_object_bound-2" class="method trait-impl"><a class="src rightside" href="../../src/pyo3/conversions/std/string.rs.html#240-242">Source</a><a href="#method.from_py_object_bound-2" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.from_py_object_bound" class="fn">from_py_object_bound</a>(ob: <a class="struct" href="../struct.Borrowed.html" title="struct pyo3::Borrowed">Borrowed</a>&lt;'a, '_, <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;Self&gt;</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-FromPyObjectBound%3C'a,+'_%3E-for-Cow%3C'a,+%5Bu8%5D%3E" class="impl"><a class="src rightside" href="../../src/pyo3/conversions/std/slice.rs.html#63-77">Source</a><a href="#impl-FromPyObjectBound%3C'a,+'_%3E-for-Cow%3C'a,+%5Bu8%5D%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.FromPyObjectBound.html" title="trait pyo3::conversion::FromPyObjectBound">FromPyObjectBound</a>&lt;'a, '_&gt; for <a class="enum" href="https://doc.rust-lang.org/1.85.1/alloc/borrow/enum.Cow.html" title="enum alloc::borrow::Cow">Cow</a>&lt;'a, [<a class="primitive" href="https://doc.rust-lang.org/1.85.1/std/primitive.u8.html">u8</a>]&gt;</h3><div class="docblock"><p>Special-purpose trait impl to efficiently handle both <code>bytes</code> and <code>bytearray</code></p>
</div></section></summary><div class="docblock"><p>If the source object is a <code>bytes</code> object, the <code>Cow</code> will be borrowed and
pointing into the source object, and no copying or heap allocations will happen.
If it is a <code>bytearray</code>, its contents will be copied to an owned <code>Cow</code>.</p>
</div><div class="impl-items"><section id="method.from_py_object_bound-3" class="method trait-impl"><a class="src rightside" href="../../src/pyo3/conversions/std/slice.rs.html#64-71">Source</a><a href="#method.from_py_object_bound-3" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.from_py_object_bound" class="fn">from_py_object_bound</a>(ob: <a class="struct" href="../struct.Borrowed.html" title="struct pyo3::Borrowed">Borrowed</a>&lt;'a, '_, <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;Self&gt;</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-FromPyObjectBound%3C'_,+'py%3E-for-T" class="impl"><a class="src rightside" href="../../src/pyo3/conversion.rs.html#530-542">Source</a><a href="#impl-FromPyObjectBound%3C'_,+'py%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;'py, T&gt; <a class="trait" href="trait.FromPyObjectBound.html" title="trait pyo3::conversion::FromPyObjectBound">FromPyObjectBound</a>&lt;'_, 'py&gt; for T<div class="where">where
T: <a class="trait" href="trait.FromPyObject.html" title="trait pyo3::conversion::FromPyObject">FromPyObject</a>&lt;'py&gt;,</div></h3></section></div><script src="../../trait.impl/pyo3/conversion/trait.FromPyObjectBound.js" data-ignore-extern-crates="std,alloc" async></script></section></div></main></body></html>