Files
google-apis-rs/google_apis_common/trait.Delegate.html
2024-03-05 21:06:01 +01:00

98 lines
23 KiB
HTML
Raw 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="A trait specifying functionality to help controlling any request performed by the API. The trait has a conservative default implementation."><title>Delegate in google_apis_common - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="google_apis_common" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.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">&#9776;</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../google_apis_common/index.html">google_apis_common</a><span class="version">6.0.1</span></h2></div><h2 class="location"><a href="#">Delegate</a></h2><div class="sidebar-elems"><section><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.api_key">api_key</a></li><li><a href="#method.begin">begin</a></li><li><a href="#method.cancel_chunk_upload">cancel_chunk_upload</a></li><li><a href="#method.chunk_size">chunk_size</a></li><li><a href="#method.finished">finished</a></li><li><a href="#method.http_error">http_error</a></li><li><a href="#method.http_failure">http_failure</a></li><li><a href="#method.pre_request">pre_request</a></li><li><a href="#method.response_json_decode_error">response_json_decode_error</a></li><li><a href="#method.store_upload_url">store_upload_url</a></li><li><a href="#method.token">token</a></li><li><a href="#method.upload_url">upload_url</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In crate google_apis_common</a></h2></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../google_apis_common/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Trait <a href="index.html">google_apis_common</a>::<wbr><a class="trait" href="#">Delegate</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../src/google_apis_common/lib.rs.html#97-221">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><pre class="rust item-decl"><code>pub trait Delegate: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> {
// Provided methods
fn <a href="#method.begin" class="fn">begin</a>(&amp;mut self, _info: <a class="struct" href="struct.MethodInfo.html" title="struct google_apis_common::MethodInfo">MethodInfo</a>) { ... }
<span class="item-spacer"></span> fn <a href="#method.http_error" class="fn">http_error</a>(&amp;mut self, _err: &amp;<a class="struct" href="../hyper/error/struct.Error.html" title="struct hyper::error::Error">Error</a>) -&gt; <a class="enum" href="enum.Retry.html" title="enum google_apis_common::Retry">Retry</a> { ... }
<span class="item-spacer"></span> fn <a href="#method.api_key" class="fn">api_key</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt; { ... }
<span class="item-spacer"></span> fn <a href="#method.token" class="fn">token</a>(
&amp;mut self,
e: <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/error/trait.Error.html" title="trait core::error::Error">StdError</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>&gt;
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;, <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/error/trait.Error.html" title="trait core::error::Error">StdError</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>&gt;&gt; { ... }
<span class="item-spacer"></span> fn <a href="#method.upload_url" class="fn">upload_url</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt; { ... }
<span class="item-spacer"></span> fn <a href="#method.store_upload_url" class="fn">store_upload_url</a>(&amp;mut self, url: <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>&gt;) { ... }
<span class="item-spacer"></span> fn <a href="#method.response_json_decode_error" class="fn">response_json_decode_error</a>(
&amp;mut self,
json_encoded_value: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>,
json_decode_error: &amp;<a class="struct" href="../serde_json/error/struct.Error.html" title="struct serde_json::error::Error">Error</a>
) { ... }
<span class="item-spacer"></span> fn <a href="#method.http_failure" class="fn">http_failure</a>(&amp;mut self, _: &amp;<a class="struct" href="../http/response/struct.Response.html" title="struct http::response::Response">Response</a>&lt;<a class="struct" href="../hyper/body/body/struct.Body.html" title="struct hyper::body::body::Body">Body</a>&gt;, _err: <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="../serde_json/value/enum.Value.html" title="enum serde_json::value::Value">Value</a>&gt;) -&gt; <a class="enum" href="enum.Retry.html" title="enum google_apis_common::Retry">Retry</a> { ... }
<span class="item-spacer"></span> fn <a href="#method.pre_request" class="fn">pre_request</a>(&amp;mut self) { ... }
<span class="item-spacer"></span> fn <a href="#method.chunk_size" class="fn">chunk_size</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u64.html">u64</a> { ... }
<span class="item-spacer"></span> fn <a href="#method.cancel_chunk_upload" class="fn">cancel_chunk_upload</a>(&amp;mut self, chunk: &amp;<a class="struct" href="struct.ContentRange.html" title="struct google_apis_common::ContentRange">ContentRange</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a> { ... }
<span class="item-spacer"></span> fn <a href="#method.finished" class="fn">finished</a>(&amp;mut self, is_success: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>) { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait specifying functionality to help controlling any request performed by the API.
The trait has a conservative default implementation.</p>
<p>It contains methods to deal with all common issues, as well with the ones related to
uploading media</p>
</div></details><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.begin" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#104">source</a><h4 class="code-header">fn <a href="#method.begin" class="fn">begin</a>(&amp;mut self, _info: <a class="struct" href="struct.MethodInfo.html" title="struct google_apis_common::MethodInfo">MethodInfo</a>)</h4></section></summary><div class="docblock"><p>Called at the beginning of any API request. The delegate should store the method
information if he is interesting in knowing more context when further calls to it
are made.
The matching <code>finished()</code> call will always be made, no matter whether or not the API
request was successful. That way, the delegate may easily maintain a clean state
between various API calls.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.http_error" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#112-114">source</a><h4 class="code-header">fn <a href="#method.http_error" class="fn">http_error</a>(&amp;mut self, _err: &amp;<a class="struct" href="../hyper/error/struct.Error.html" title="struct hyper::error::Error">Error</a>) -&gt; <a class="enum" href="enum.Retry.html" title="enum google_apis_common::Retry">Retry</a></h4></section></summary><div class="docblock"><p>Called whenever there is an <a href="../hyper/error/struct.Error.html" title="struct hyper::error::Error">HttpError</a>, usually if there are network problems.</p>
<p>If you choose to retry after a duration, the duration should be chosen using the
<a href="http://en.wikipedia.org/wiki/Exponential_backoff">exponential backoff algorithm</a>.</p>
<p>Return retry information.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.api_key" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#119-121">source</a><h4 class="code-header">fn <a href="#method.api_key" class="fn">api_key</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;</h4></section></summary><div class="docblock"><p>Called whenever there is the need for your applications API key after
the official authenticator implementation didnt provide one, for some reason.
If this method returns None as well, the underlying operation will fail</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.token" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#128-133">source</a><h4 class="code-header">fn <a href="#method.token" class="fn">token</a>(
&amp;mut self,
e: <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/error/trait.Error.html" title="trait core::error::Error">StdError</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>&gt;
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;, <a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;dyn <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/error/trait.Error.html" title="trait core::error::Error">StdError</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Called whenever the Authenticator didnt yield a token. The delegate
may attempt to provide one, or just take it as a general information about the
impending failure.
The given Error provides information about why the token couldnt be acquired in the
first place</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.upload_url" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#142-144">source</a><h4 class="code-header">fn <a href="#method.upload_url" class="fn">upload_url</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.76.0/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;</h4></section></summary><div class="docblock"><p>Called during resumable uploads to provide a URL for the impending upload.
It was saved after a previous call to <code>store_upload_url(...)</code>, and if not None,
will be used instead of asking the server for a new upload URL.
This is useful in case a previous resumable upload was aborted/canceled, but should now
be resumed.
The returned URL will be used exactly once - if it fails again and the delegate allows
to retry, we will ask the server for a new upload URL.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.store_upload_url" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#152-154">source</a><h4 class="code-header">fn <a href="#method.store_upload_url" class="fn">store_upload_url</a>(&amp;mut self, url: <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>&gt;)</h4></section></summary><div class="docblock"><p>Called after we have retrieved a new upload URL for a resumable upload to store it
in case we fail or cancel. That way, we can attempt to resume the upload later,
see <code>upload_url()</code>.
It will also be called with None after a successful upload, which allows the delegate
to forget the URL. That way, we will not attempt to resume an upload that has already
finished.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.response_json_decode_error" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#164-171">source</a><h4 class="code-header">fn <a href="#method.response_json_decode_error" class="fn">response_json_decode_error</a>(
&amp;mut self,
json_encoded_value: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.str.html">str</a>,
json_decode_error: &amp;<a class="struct" href="../serde_json/error/struct.Error.html" title="struct serde_json::error::Error">Error</a>
)</h4></section></summary><div class="docblock"><p>Called whenever a server response could not be decoded from json.
Its for informational purposes only, the caller will return with an error
accordingly.</p>
<h5 id="arguments"><a href="#arguments">Arguments</a></h5>
<ul>
<li><code>json_encoded_value</code> - The json-encoded value which failed to decode.</li>
<li><code>json_decode_error</code> - The decoder error</li>
</ul>
</div></details><details class="toggle method-toggle" open><summary><section id="method.http_failure" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#181-187">source</a><h4 class="code-header">fn <a href="#method.http_failure" class="fn">http_failure</a>(&amp;mut self, _: &amp;<a class="struct" href="../http/response/struct.Response.html" title="struct http::response::Response">Response</a>&lt;<a class="struct" href="../hyper/body/body/struct.Body.html" title="struct hyper::body::body::Body">Body</a>&gt;, _err: <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="../serde_json/value/enum.Value.html" title="enum serde_json::value::Value">Value</a>&gt;) -&gt; <a class="enum" href="enum.Retry.html" title="enum google_apis_common::Retry">Retry</a></h4></section></summary><div class="docblock"><p>Called whenever the http request returns with a non-success status code.
This can involve authentication issues, or anything else that very much
depends on the used API method.
The delegate should check the status, header and decoded json error to decide
whether to retry or not. In the latter case, the underlying call will fail.</p>
<p>If you choose to retry after a duration, the duration should be chosen using the
<a href="http://en.wikipedia.org/wiki/Exponential_backoff">exponential backoff algorithm</a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.pre_request" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#192">source</a><h4 class="code-header">fn <a href="#method.pre_request" class="fn">pre_request</a>(&amp;mut self)</h4></section></summary><div class="docblock"><p>Called prior to sending the main request of the given method. It can be used to time
the call or to print progress information.
Its also useful as you can be sure that a request will definitely be made.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.chunk_size" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#197-199">source</a><h4 class="code-header">fn <a href="#method.chunk_size" class="fn">chunk_size</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u64.html">u64</a></h4></section></summary><div class="docblock"><p>Return the size of each chunk of a resumable upload.
Must be a power of two, with 1&lt;&lt;18 being the smallest allowed chunk size.
Will be called once before starting any resumable upload.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.cancel_chunk_upload" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#205-208">source</a><h4 class="code-header">fn <a href="#method.cancel_chunk_upload" class="fn">cancel_chunk_upload</a>(&amp;mut self, chunk: &amp;<a class="struct" href="struct.ContentRange.html" title="struct google_apis_common::ContentRange">ContentRange</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Called before the given chunk is uploaded to the server.
If true is returned, the upload will be interrupted.
However, it may be resumable if you stored the upload URL in a previous call
to <code>store_upload_url()</code></p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.finished" class="method"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#218-220">source</a><h4 class="code-header">fn <a href="#method.finished" class="fn">finished</a>(&amp;mut self, is_success: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>)</h4></section></summary><div class="docblock"><p>Called before the API request method returns, in every case. It can be used to clean up
internal state between calls to the API.
This call always has a matching call to <code>begin(...)</code>.</p>
<h5 id="arguments-1"><a href="#arguments-1">Arguments</a></h5>
<ul>
<li><code>is_success</code> - a true value indicates the operation was successful. If false, you should
discard all values stored during <code>store_upload_url</code>.</li>
</ul>
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-Delegate-for-DefaultDelegate" class="impl"><a class="src rightside" href="../src/google_apis_common/lib.rs.html#228">source</a><a href="#impl-Delegate-for-DefaultDelegate" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Delegate.html" title="trait google_apis_common::Delegate">Delegate</a> for <a class="struct" href="struct.DefaultDelegate.html" title="struct google_apis_common::DefaultDelegate">DefaultDelegate</a></h3></section></div><script src="../trait.impl/google_apis_common/trait.Delegate.js" async></script></section></div></main></body></html>