1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

Deploying to gh-pages from @ fc6563a019 🚀

This commit is contained in:
robjtede 2021-03-23 22:38:11 +00:00
parent 3d2bc36741
commit afa560c27a
10 changed files with 328 additions and 142 deletions

View File

@ -1,21 +1,32 @@
<!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="API documentation for the Rust `SessionStatus` enum in crate `actix_session`."><meta name="keywords" content="rust, rustlang, rust-lang, SessionStatus"><title>actix_session::SessionStatus - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<!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="Status of a [`Session`]."><meta name="keywords" content="rust, rustlang, rust-lang, SessionStatus"><title>actix_session::SessionStatus - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc enum"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a href='../actix_session/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Enum SessionStatus</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#variants">Variants</a><div class="sidebar-links"><a href="#variant.Changed">Changed</a><a href="#variant.Purged">Purged</a><a href="#variant.Renewed">Renewed</a><a href="#variant.Unchanged">Unchanged</a></div><a class="sidebar-title" href="#trait-implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Clone">Clone</a><a href="#impl-Debug">Debug</a><a href="#impl-Default">Default</a><a href="#impl-PartialEq%3CSessionStatus%3E">PartialEq&lt;SessionStatus&gt;</a><a href="#impl-StructuralPartialEq">StructuralPartialEq</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-RefUnwindSafe">RefUnwindSafe</a><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">UnwindSafe</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow&lt;T&gt;</a><a href="#impl-BorrowMut%3CT%3E">BorrowMut&lt;T&gt;</a><a href="#impl-From%3CT%3E">From&lt;T&gt;</a><a href="#impl-Instrument">Instrument</a><a href="#impl-Into%3CU%3E">Into&lt;U&gt;</a><a href="#impl-Same%3CT%3E">Same&lt;T&gt;</a><a href="#impl-ToOwned">ToOwned</a><a href="#impl-TryFrom%3CU%3E">TryFrom&lt;U&gt;</a><a href="#impl-TryInto%3CU%3E">TryInto&lt;U&gt;</a><a href="#impl-VZip%3CV%3E">VZip&lt;V&gt;</a></div></div><p class="location"><a href="index.html">actix_session</a></p><div id="sidebar-vars" data-name="SessionStatus" data-ty="enum" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Enum <a href="index.html">actix_session</a>::<wbr><a class="enum" href="">SessionStatus</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/lib.rs.html#104-109" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust enum">pub enum SessionStatus {
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Enum <a href="index.html">actix_session</a>::<wbr><a class="enum" href="">SessionStatus</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/lib.rs.html#112-133" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust enum">pub enum SessionStatus {
Changed,
Purged,
Renewed,
Unchanged,
}</pre></div><h2 id="variants" class="variants small-section-header">
}</pre></div><div class="docblock"><p>Status of a <a href="../actix_session/struct.Session.html" title="Session"><code>Session</code></a>.</p>
</div><h2 id="variants" class="variants small-section-header">
Variants<a href="#variants" class="anchor"></a></h2>
<div id="variant.Changed" class="variant small-section-header"><a href="#variant.Changed" class="anchor field"></a><code>Changed</code></div><div id="variant.Purged" class="variant small-section-header"><a href="#variant.Purged" class="anchor field"></a><code>Purged</code></div><div id="variant.Renewed" class="variant small-section-header"><a href="#variant.Renewed" class="anchor field"></a><code>Renewed</code></div><div id="variant.Unchanged" class="variant small-section-header"><a href="#variant.Unchanged" class="anchor field"></a><code>Unchanged</code></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-Clone" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Clone" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#103" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.clone" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone" class="fnname">clone</a>(&amp;self) -&gt; <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#103" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
<div id="variant.Changed" class="variant small-section-header"><a href="#variant.Changed" class="anchor field"></a><code>Changed</code></div><div class="docblock"><p>Session has been updated and requires a new persist operation.</p>
</div><div id="variant.Purged" class="variant small-section-header"><a href="#variant.Purged" class="anchor field"></a><code>Purged</code></div><div class="docblock"><p>Session is flagged for deletion and should be removed from client and server.</p>
<p>Most operations on the session after purge flag is set should have no effect.</p>
</div><div id="variant.Renewed" class="variant small-section-header"><a href="#variant.Renewed" class="anchor field"></a><code>Renewed</code></div><div class="docblock"><p>Session is flagged for refresh.</p>
<p>For example, when using a backend that has a TTL (time-to-live) expiry on the session entry,
the session will be refreshed even if no data inside it has changed. The client may also
be notified of the refresh.</p>
</div><div id="variant.Unchanged" class="variant small-section-header"><a href="#variant.Unchanged" class="anchor field"></a><code>Unchanged</code></div><div class="docblock"><p>Session is unchanged from when last seen (if exists).</p>
<p>This state also captures new (previously unissued) sessions such as a users first
site visit.</p>
</div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-Clone" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Clone" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#111" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.clone" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone" class="fnname">clone</a>(&amp;self) -&gt; <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#111" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
</div><h4 id="method.clone_from" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from" class="fnname">clone_from</a>(&amp;mut self, source: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>Self)</code><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/clone.rs.html#130" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
</div></div><h3 id="impl-Debug" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Debug" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#103" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.fmt" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#103" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id="impl-Default" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Default" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#110-114" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.default" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default" class="fnname">default</a>() -&gt; <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#111-113" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default">Read more</a></p>
</div></div><h3 id="impl-PartialEq%3CSessionStatus%3E" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>&lt;<a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a>&gt; for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-PartialEq%3CSessionStatus%3E" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#103" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.eq" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq" class="fnname">eq</a>(&amp;self, other: &amp;<a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#103" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used
</div></div><h3 id="impl-Debug" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Debug" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#111" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.fmt" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#111" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id="impl-Default" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Default" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#135-139" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.default" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default" class="fnname">default</a>() -&gt; <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#136-138" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default">Read more</a></p>
</div></div><h3 id="impl-PartialEq%3CSessionStatus%3E" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>&lt;<a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a>&gt; for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-PartialEq%3CSessionStatus%3E" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#111" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.eq" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq" class="fnname">eq</a>(&amp;self, other: &amp;<a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#111" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used
by <code>==</code>. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id="method.ne" class="method hidden"><code><span class="docblock attributes">#[must_use]</span>pub fn <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne" class="fnname">ne</a>(&amp;self, other: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#213" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 id="impl-StructuralPartialEq" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.StructuralPartialEq.html" title="trait core::marker::StructuralPartialEq">StructuralPartialEq</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-StructuralPartialEq" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#103" title="goto source code">[src]</a></h3><div class="impl-items"></div></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><h3 id="impl-RefUnwindSafe" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-RefUnwindSafe" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Send" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Send" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Sync" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Sync" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Unpin" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Unpin" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-UnwindSafe" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-UnwindSafe" class="anchor"></a></h3><div class="impl-items"></div></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><h3 id="impl-Any" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-Any" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#131-135" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.type_id" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#132" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></div><h3 id="impl-StructuralPartialEq" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.StructuralPartialEq.html" title="trait core::marker::StructuralPartialEq">StructuralPartialEq</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-StructuralPartialEq" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#111" title="goto source code">[src]</a></h3><div class="impl-items"></div></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><h3 id="impl-RefUnwindSafe" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-RefUnwindSafe" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Send" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Send" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Sync" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Sync" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Unpin" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-Unpin" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-UnwindSafe" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a></code><a href="#impl-UnwindSafe" class="anchor"></a></h3><div class="impl-items"></div></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><h3 id="impl-Any" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-Any" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#131-135" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.type_id" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#132" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></div><h3 id="impl-Borrow%3CT%3E" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-Borrow%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#208-213" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.borrow" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#210" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></div><h3 id="impl-BorrowMut%3CT%3E" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-BorrowMut%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#216-220" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.borrow_mut" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#217" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
</div></div><h3 id="impl-From%3CT%3E" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</code><a href="#impl-From%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#544-548" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.from" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -&gt; T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#545" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>

View File

@ -1,7 +1,7 @@
<!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="Sessions for Actix Web."><meta name="keywords" content="rust, rustlang, rust-lang, actix_session"><title>actix_session - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a href='../actix_session/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Crate actix_session</p><div class="block version"><p>Version 0.4.1</p></div><div class="sidebar-elems"><a id="all-types" href="all.html"><p>See all actix_session's items</p></a><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li></ul></div><p class="location"></p><div id="sidebar-vars" data-name="actix_session" data-ty="mod" data-relpath="../"></div></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Crate <a class="mod" href="">actix_session</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/lib.rs.html#1-332" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Sessions for Actix Web.</p>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Crate <a class="mod" href="">actix_session</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/lib.rs.html#1-411" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Sessions for Actix Web.</p>
<p>Provides a general solution for session management. Session middleware could provide different
implementations which could be accessed via general session API.</p>
<p>This crate provides a general solution for session management and includes a cookie backend.
@ -18,9 +18,9 @@ modifying session data.</p>
<span class="comment">// access session data</span>
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">count</span>) <span class="op">=</span> <span class="ident">session</span>.<span class="ident">get</span>::<span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span>(<span class="string">&quot;counter&quot;</span>)<span class="question-mark">?</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;SESSION value: {}&quot;</span>, <span class="ident">count</span>);
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="ident">count</span> <span class="op">+</span> <span class="number">1</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="ident">count</span> <span class="op">+</span> <span class="number">1</span>)<span class="question-mark">?</span>;
} <span class="kw">else</span> {
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">1</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">1</span>)<span class="question-mark">?</span>;
}
<span class="prelude-val">Ok</span>(<span class="string">&quot;Welcome!&quot;</span>)
@ -41,7 +41,8 @@ modifying session data.</p>
<table><tr class="module-item"><td><a class="struct" href="struct.CookieSession.html" title="actix_session::CookieSession struct">CookieSession</a></td><td class="docblock-short"><p>Use cookies for session storage.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.Session.html" title="actix_session::Session struct">Session</a></td><td class="docblock-short"><p>The high-level interface you use to modify session data.</p>
</td></tr></table><h2 id="enums" class="section-header"><a href="#enums">Enums</a></h2>
<table><tr class="module-item"><td><a class="enum" href="enum.SessionStatus.html" title="actix_session::SessionStatus enum">SessionStatus</a></td><td class="docblock-short"></td></tr></table><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2>
<table><tr class="module-item"><td><a class="enum" href="enum.SessionStatus.html" title="actix_session::SessionStatus enum">SessionStatus</a></td><td class="docblock-short"><p>Status of a <a href="../actix_session/struct.Session.html" title="Session"><code>Session</code></a>.</p>
</td></tr></table><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2>
<table><tr class="module-item"><td><a class="trait" href="trait.UserSession.html" title="actix_session::UserSession trait">UserSession</a></td><td class="docblock-short"><p>Extraction of a <a href="../actix_session/struct.Session.html" title="Session"><code>Session</code></a> object.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="actix_session" data-search-js="../search-index.js"></div>
<script src="../main.js"></script></body></html>

View File

@ -1 +1 @@
initSidebarItems({"enum":[["SessionStatus",""]],"struct":[["CookieSession","Use cookies for session storage."],["Session","The high-level interface you use to modify session data."]],"trait":[["UserSession","Extraction of a [`Session`] object."]]});
initSidebarItems({"enum":[["SessionStatus","Status of a [`Session`]."]],"struct":[["CookieSession","Use cookies for session storage."],["Session","The high-level interface you use to modify session data."]],"trait":[["UserSession","Extraction of a [`Session`] object."]]});

View File

@ -1,7 +1,7 @@
<!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="Use cookies for session storage."><meta name="keywords" content="rust, rustlang, rust-lang, CookieSession"><title>actix_session::CookieSession - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a href='../actix_session/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Struct CookieSession</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#implementations">Methods</a><div class="sidebar-links"><a href="#method.domain">domain</a><a href="#method.expires_in">expires_in</a><a href="#method.expires_in_time">expires_in_time</a><a href="#method.http_only">http_only</a><a href="#method.lazy">lazy</a><a href="#method.max_age">max_age</a><a href="#method.max_age_time">max_age_time</a><a href="#method.name">name</a><a href="#method.path">path</a><a href="#method.private">private</a><a href="#method.same_site">same_site</a><a href="#method.secure">secure</a><a href="#method.signed">signed</a></div><a class="sidebar-title" href="#trait-implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Transform%3CS%2C%20ServiceRequest%3E">Transform&lt;S, ServiceRequest&gt;</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-RefUnwindSafe">!RefUnwindSafe</a><a href="#impl-Send">!Send</a><a href="#impl-Sync">!Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">UnwindSafe</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow&lt;T&gt;</a><a href="#impl-BorrowMut%3CT%3E">BorrowMut&lt;T&gt;</a><a href="#impl-From%3CT%3E">From&lt;T&gt;</a><a href="#impl-Instrument">Instrument</a><a href="#impl-Into%3CU%3E">Into&lt;U&gt;</a><a href="#impl-Same%3CT%3E">Same&lt;T&gt;</a><a href="#impl-TryFrom%3CU%3E">TryFrom&lt;U&gt;</a><a href="#impl-TryInto%3CU%3E">TryInto&lt;U&gt;</a><a href="#impl-VZip%3CV%3E">VZip&lt;V&gt;</a></div></div><p class="location"><a href="index.html">actix_session</a></p><div id="sidebar-vars" data-name="CookieSession" data-ty="struct" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Struct <a href="index.html">actix_session</a>::<wbr><a class="struct" href="">CookieSession</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/cookie.rs.html#198" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust struct">pub struct CookieSession(_);</pre></div><div class="docblock"><p>Use cookies for session storage.</p>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Struct <a href="index.html">actix_session</a>::<wbr><a class="struct" href="">CookieSession</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/cookie.rs.html#201" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust struct">pub struct CookieSession(_);</pre></div><div class="docblock"><p>Use cookies for session storage.</p>
<p><code>CookieSession</code> creates sessions which are limited to storing
fewer than 4000 bytes of data (as the payload must fit into a single
cookie). An Internal Server Error is generated if the session contains more
@ -32,31 +32,31 @@ cause troubles when reading cookie, if they are not properly percent encoded.</p
.<span class="ident">path</span>(<span class="string">&quot;/&quot;</span>)
.<span class="ident">secure</span>(<span class="bool-val">true</span>))
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">HttpResponse</span>::<span class="prelude-val">Ok</span>()));</pre></div>
</div><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><h3 id="impl" class="impl"><code class="in-band">impl <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a href="#impl" class="anchor"></a><a class="srclink" href="../src/actix_session/cookie.rs.html#200-290" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.signed" class="method"><code>pub fn <a href="#method.signed" class="fnname">signed</a>(key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#204-209" title="goto source code">[src]</a></h4><div class="docblock"><p>Construct new <em>signed</em> <code>CookieSession</code> instance.</p>
</div><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><h3 id="impl" class="impl"><code class="in-band">impl <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a href="#impl" class="anchor"></a><a class="srclink" href="../src/actix_session/cookie.rs.html#203-293" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.signed" class="method"><code>pub fn <a href="#method.signed" class="fnname">signed</a>(key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#207-212" title="goto source code">[src]</a></h4><div class="docblock"><p>Construct new <em>signed</em> <code>CookieSession</code> instance.</p>
<p>Panics if key length is less than 32 bytes.</p>
</div><h4 id="method.private" class="method"><code>pub fn <a href="#method.private" class="fnname">private</a>(key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#214-219" title="goto source code">[src]</a></h4><div class="docblock"><p>Construct new <em>private</em> <code>CookieSession</code> instance.</p>
</div><h4 id="method.private" class="method"><code>pub fn <a href="#method.private" class="fnname">private</a>(key: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#217-222" title="goto source code">[src]</a></h4><div class="docblock"><p>Construct new <em>private</em> <code>CookieSession</code> instance.</p>
<p>Panics if key length is less than 32 bytes.</p>
</div><h4 id="method.path" class="method"><code>pub fn <a href="#method.path" class="fnname">path</a>&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;(self, value: S) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#222-225" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>path</code> field in the session cookie being built.</p>
</div><h4 id="method.name" class="method"><code>pub fn <a href="#method.name" class="fnname">name</a>&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;(self, value: S) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#228-231" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>name</code> field in the session cookie being built.</p>
</div><h4 id="method.domain" class="method"><code>pub fn <a href="#method.domain" class="fnname">domain</a>&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;(self, value: S) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#234-237" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>domain</code> field in the session cookie being built.</p>
</div><h4 id="method.lazy" class="method"><code>pub fn <a href="#method.lazy" class="fnname">lazy</a>(self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#243-246" title="goto source code">[src]</a></h4><div class="docblock"><p>When true, prevents adding session cookies to responses until
</div><h4 id="method.path" class="method"><code>pub fn <a href="#method.path" class="fnname">path</a>&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;(self, value: S) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#225-228" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>path</code> field in the session cookie being built.</p>
</div><h4 id="method.name" class="method"><code>pub fn <a href="#method.name" class="fnname">name</a>&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;(self, value: S) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#231-234" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>name</code> field in the session cookie being built.</p>
</div><h4 id="method.domain" class="method"><code>pub fn <a href="#method.domain" class="fnname">domain</a>&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;(self, value: S) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#237-240" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>domain</code> field in the session cookie being built.</p>
</div><h4 id="method.lazy" class="method"><code>pub fn <a href="#method.lazy" class="fnname">lazy</a>(self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#246-249" title="goto source code">[src]</a></h4><div class="docblock"><p>When true, prevents adding session cookies to responses until
the session contains data. Default is <code>false</code>.</p>
<p>Useful when trying to comply with laws that require consent for setting cookies.</p>
</div><h4 id="method.secure" class="method"><code>pub fn <a href="#method.secure" class="fnname">secure</a>(self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#252-255" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>secure</code> field in the session cookie being built.</p>
</div><h4 id="method.secure" class="method"><code>pub fn <a href="#method.secure" class="fnname">secure</a>(self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#255-258" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>secure</code> field in the session cookie being built.</p>
<p>If the <code>secure</code> field is set, a cookie will only be transmitted when the
connection is secure - i.e. <code>https</code></p>
</div><h4 id="method.http_only" class="method"><code>pub fn <a href="#method.http_only" class="fnname">http_only</a>(self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#258-261" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>http_only</code> field in the session cookie being built.</p>
</div><h4 id="method.same_site" class="method"><code>pub fn <a href="#method.same_site" class="fnname">same_site</a>(self, value: <a class="enum" href="https://docs.rs/cookie/0.14/cookie/draft/enum.SameSite.html" title="enum cookie::draft::SameSite">SameSite</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#264-267" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>same_site</code> field in the session cookie being built.</p>
</div><h4 id="method.max_age" class="method"><code>pub fn <a href="#method.max_age" class="fnname">max_age</a>(self, seconds: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#270-272" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>max-age</code> field in the session cookie being built.</p>
</div><h4 id="method.max_age_time" class="method"><code>pub fn <a href="#method.max_age_time" class="fnname">max_age_time</a>(self, value: Duration) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#275-278" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>max-age</code> field in the session cookie being built.</p>
</div><h4 id="method.expires_in" class="method"><code>pub fn <a href="#method.expires_in" class="fnname">expires_in</a>(self, seconds: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#281-283" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>expires</code> field in the session cookie being built.</p>
</div><h4 id="method.expires_in_time" class="method"><code>pub fn <a href="#method.expires_in_time" class="fnname">expires_in_time</a>(self, value: Duration) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#286-289" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>expires</code> field in the session cookie being built.</p>
</div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-Transform%3CS%2C%20ServiceRequest%3E" class="impl"><code class="in-band">impl&lt;S, B:&nbsp;'static&gt; Transform&lt;S, ServiceRequest&gt; for <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: Service&lt;ServiceRequest, Response = ServiceResponse&lt;B&gt;&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;S::Future: 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;S::Error: 'static,&nbsp;</span></code><a href="#impl-Transform%3CS%2C%20ServiceRequest%3E" class="anchor"></a><a class="srclink" href="../src/actix_session/cookie.rs.html#292-310" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Response" class="type"><code>type <a href="#associatedtype.Response" class="type">Response</a> = ServiceResponse&lt;B&gt;</code></h4><div class='docblock'><p>Responses produced by the service.</p>
</div><h4 id="method.http_only" class="method"><code>pub fn <a href="#method.http_only" class="fnname">http_only</a>(self, value: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#261-264" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>http_only</code> field in the session cookie being built.</p>
</div><h4 id="method.same_site" class="method"><code>pub fn <a href="#method.same_site" class="fnname">same_site</a>(self, value: <a class="enum" href="https://docs.rs/cookie/0.14/cookie/draft/enum.SameSite.html" title="enum cookie::draft::SameSite">SameSite</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#267-270" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>same_site</code> field in the session cookie being built.</p>
</div><h4 id="method.max_age" class="method"><code>pub fn <a href="#method.max_age" class="fnname">max_age</a>(self, seconds: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#273-275" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>max-age</code> field in the session cookie being built.</p>
</div><h4 id="method.max_age_time" class="method"><code>pub fn <a href="#method.max_age_time" class="fnname">max_age_time</a>(self, value: Duration) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#278-281" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>max-age</code> field in the session cookie being built.</p>
</div><h4 id="method.expires_in" class="method"><code>pub fn <a href="#method.expires_in" class="fnname">expires_in</a>(self, seconds: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a>) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#284-286" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>expires</code> field in the session cookie being built.</p>
</div><h4 id="method.expires_in_time" class="method"><code>pub fn <a href="#method.expires_in_time" class="fnname">expires_in_time</a>(self, value: Duration) -&gt; <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a class="srclink" href="../src/actix_session/cookie.rs.html#289-292" title="goto source code">[src]</a></h4><div class="docblock"><p>Sets the <code>expires</code> field in the session cookie being built.</p>
</div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-Transform%3CS%2C%20ServiceRequest%3E" class="impl"><code class="in-band">impl&lt;S, B:&nbsp;'static&gt; Transform&lt;S, ServiceRequest&gt; for <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: Service&lt;ServiceRequest, Response = ServiceResponse&lt;B&gt;&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;S::Future: 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;S::Error: 'static,&nbsp;</span></code><a href="#impl-Transform%3CS%2C%20ServiceRequest%3E" class="anchor"></a><a class="srclink" href="../src/actix_session/cookie.rs.html#295-313" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Response" class="type"><code>type <a href="#associatedtype.Response" class="type">Response</a> = ServiceResponse&lt;B&gt;</code></h4><div class='docblock'><p>Responses produced by the service.</p>
</div><h4 id="associatedtype.Error" class="type"><code>type <a href="#associatedtype.Error" class="type">Error</a> = S::Error</code></h4><div class='docblock'><p>Errors produced by the service.</p>
</div><h4 id="associatedtype.InitError" class="type"><code>type <a href="#associatedtype.InitError" class="type">InitError</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a></code></h4><div class='docblock'><p>Errors produced while building a transform service.</p>
</div><h4 id="associatedtype.Transform" class="type"><code>type <a href="#associatedtype.Transform" class="type">Transform</a> = CookieSessionMiddleware&lt;S&gt;</code></h4><div class='docblock'><p>The <code>TransformService</code> value created by this factory</p>
</div><h4 id="associatedtype.Future" class="type"><code>type <a href="#associatedtype.Future" class="type">Future</a> = Ready&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::Transform, Self::InitError&gt;&gt;</code></h4><div class='docblock'><p>The future response value.</p>
</div><h4 id="method.new_transform" class="method hidden"><code>fn <a href="#method.new_transform" class="fnname">new_transform</a>(&amp;self, service: S) -&gt; Self::Future</code><a class="srclink" href="../src/actix_session/cookie.rs.html#304-309" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Creates and returns a new Transform component, asynchronously</p>
</div><h4 id="method.new_transform" class="method hidden"><code>fn <a href="#method.new_transform" class="fnname">new_transform</a>(&amp;self, service: S) -&gt; Self::Future</code><a class="srclink" href="../src/actix_session/cookie.rs.html#307-312" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Creates and returns a new Transform component, asynchronously</p>
</div></div></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><h3 id="impl-RefUnwindSafe" class="impl"><code class="in-band">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a href="#impl-RefUnwindSafe" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Send" class="impl"><code class="in-band">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a href="#impl-Send" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Sync" class="impl"><code class="in-band">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a href="#impl-Sync" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Unpin" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a href="#impl-Unpin" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-UnwindSafe" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="struct" href="../actix_session/struct.CookieSession.html" title="struct actix_session::CookieSession">CookieSession</a></code><a href="#impl-UnwindSafe" class="anchor"></a></h3><div class="impl-items"></div></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><h3 id="impl-Any" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-Any" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#131-135" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.type_id" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#132" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></div><h3 id="impl-Borrow%3CT%3E" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-Borrow%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#208-213" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.borrow" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#210" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></div><h3 id="impl-BorrowMut%3CT%3E" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-BorrowMut%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#216-220" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.borrow_mut" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#217" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>

View File

@ -1,7 +1,7 @@
<!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="The high-level interface you use to modify session data."><meta name="keywords" content="rust, rustlang, rust-lang, Session"><title>actix_session::Session - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a href='../actix_session/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Struct Session</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#implementations">Methods</a><div class="sidebar-links"><a href="#method.clear">clear</a><a href="#method.get">get</a><a href="#method.get_changes">get_changes</a><a href="#method.purge">purge</a><a href="#method.remove">remove</a><a href="#method.renew">renew</a><a href="#method.set">set</a><a href="#method.set_session">set_session</a></div><a class="sidebar-title" href="#trait-implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-FromRequest">FromRequest</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-RefUnwindSafe">!RefUnwindSafe</a><a href="#impl-Send">!Send</a><a href="#impl-Sync">!Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">!UnwindSafe</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow&lt;T&gt;</a><a href="#impl-BorrowMut%3CT%3E">BorrowMut&lt;T&gt;</a><a href="#impl-From%3CT%3E">From&lt;T&gt;</a><a href="#impl-Instrument">Instrument</a><a href="#impl-Into%3CU%3E">Into&lt;U&gt;</a><a href="#impl-Same%3CT%3E">Same&lt;T&gt;</a><a href="#impl-TryFrom%3CU%3E">TryFrom&lt;U&gt;</a><a href="#impl-TryInto%3CU%3E">TryInto&lt;U&gt;</a><a href="#impl-VZip%3CV%3E">VZip&lt;V&gt;</a></div></div><p class="location"><a href="index.html">actix_session</a></p><div id="sidebar-vars" data-name="Session" data-ty="struct" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Struct <a href="index.html">actix_session</a>::<wbr><a class="struct" href="">Session</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/lib.rs.html#78" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust struct">pub struct Session(_);</pre></div><div class="docblock"><p>The high-level interface you use to modify session data.</p>
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a href='../actix_session/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Struct Session</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#implementations">Methods</a><div class="sidebar-links"><a href="#method.clear">clear</a><a href="#method.entries">entries</a><a href="#method.get">get</a><a href="#method.get_changes">get_changes</a><a href="#method.insert">insert</a><a href="#method.purge">purge</a><a href="#method.remove">remove</a><a href="#method.remove_as">remove_as</a><a href="#method.renew">renew</a><a href="#method.set_session">set_session</a></div><a class="sidebar-title" href="#trait-implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-FromRequest">FromRequest</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-RefUnwindSafe">!RefUnwindSafe</a><a href="#impl-Send">!Send</a><a href="#impl-Sync">!Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">!UnwindSafe</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow&lt;T&gt;</a><a href="#impl-BorrowMut%3CT%3E">BorrowMut&lt;T&gt;</a><a href="#impl-From%3CT%3E">From&lt;T&gt;</a><a href="#impl-Instrument">Instrument</a><a href="#impl-Into%3CU%3E">Into&lt;U&gt;</a><a href="#impl-Same%3CT%3E">Same&lt;T&gt;</a><a href="#impl-TryFrom%3CU%3E">TryFrom&lt;U&gt;</a><a href="#impl-TryInto%3CU%3E">TryInto&lt;U&gt;</a><a href="#impl-VZip%3CV%3E">VZip&lt;V&gt;</a></div></div><p class="location"><a href="index.html">actix_session</a></p><div id="sidebar-vars" data-name="Session" data-ty="struct" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Struct <a href="index.html">actix_session</a>::<wbr><a class="struct" href="">Session</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/lib.rs.html#84" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust struct">pub struct Session(_);</pre></div><div class="docblock"><p>The high-level interface you use to modify session data.</p>
<p>Session object is obtained with <a href="../actix_session/trait.UserSession.html#tymethod.get_session" title="UserSession::get_session"><code>UserSession::get_session</code></a>. The <a href="../actix_session/trait.UserSession.html" title="UserSession"><code>UserSession</code></a> trait is
implemented for <code>HttpRequest</code>, <code>ServiceRequest</code>, and <code>RequestHead</code>.</p>
@ -12,20 +12,28 @@ implemented for <code>HttpRequest</code>, <code>ServiceRequest</code>, and <code
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">index</span>(<span class="ident">session</span>: <span class="ident">Session</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> <span class="ident">str</span><span class="op">&gt;</span> {
<span class="comment">// access session data</span>
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">count</span>) <span class="op">=</span> <span class="ident">session</span>.<span class="ident">get</span>::<span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span>(<span class="string">&quot;counter&quot;</span>)<span class="question-mark">?</span> {
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="ident">count</span> <span class="op">+</span> <span class="number">1</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="ident">count</span> <span class="op">+</span> <span class="number">1</span>)<span class="question-mark">?</span>;
} <span class="kw">else</span> {
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">1</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">1</span>)<span class="question-mark">?</span>;
}
<span class="prelude-val">Ok</span>(<span class="string">&quot;Welcome!&quot;</span>)
}</pre></div>
</div><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><h3 id="impl" class="impl"><code class="in-band">impl <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#122-229" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.get" class="method"><code>pub fn <a href="#method.get" class="fnname">get</a>&lt;T:&nbsp;<a class="trait" href="https://docs.rs/serde/1.0.125/serde/de/trait.DeserializeOwned.html" title="trait serde::de::DeserializeOwned">DeserializeOwned</a>&gt;(&amp;self, key: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;T&gt;, Error&gt;</code><a class="srclink" href="../src/actix_session/lib.rs.html#124-130" title="goto source code">[src]</a></h4><div class="docblock"><p>Get a <code>value</code> from the session.</p>
</div><h4 id="method.set" class="method"><code>pub fn <a href="#method.set" class="fnname">set</a>&lt;T:&nbsp;<a class="trait" href="https://docs.rs/serde/1.0.125/serde/ser/trait.Serialize.html" title="trait serde::ser::Serialize">Serialize</a>&gt;(&amp;self, key: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, value: T) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt;</code><a class="srclink" href="../src/actix_session/lib.rs.html#133-142" title="goto source code">[src]</a></h4><div class="docblock"><p>Set a <code>value</code> from the session.</p>
</div><h4 id="method.remove" class="method"><code>pub fn <a href="#method.remove" class="fnname">remove</a>(&amp;self, key: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>)</code><a class="srclink" href="../src/actix_session/lib.rs.html#145-151" title="goto source code">[src]</a></h4><div class="docblock"><p>Remove value from the session.</p>
</div><h4 id="method.clear" class="method"><code>pub fn <a href="#method.clear" class="fnname">clear</a>(&amp;self)</code><a class="srclink" href="../src/actix_session/lib.rs.html#154-160" title="goto source code">[src]</a></h4><div class="docblock"><p>Clear the session.</p>
</div><h4 id="method.purge" class="method"><code>pub fn <a href="#method.purge" class="fnname">purge</a>(&amp;self)</code><a class="srclink" href="../src/actix_session/lib.rs.html#163-167" title="goto source code">[src]</a></h4><div class="docblock"><p>Removes session, both client and server side.</p>
</div><h4 id="method.renew" class="method"><code>pub fn <a href="#method.renew" class="fnname">renew</a>(&amp;self)</code><a class="srclink" href="../src/actix_session/lib.rs.html#170-175" title="goto source code">[src]</a></h4><div class="docblock"><p>Renews the session key, assigning existing session state to new key.</p>
</div><h4 id="method.set_session" class="method"><code>pub fn <a href="#method.set_session" class="fnname">set_session</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;data: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>&lt;Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;req: &amp;mut ServiceRequest<br>)</code><a class="srclink" href="../src/actix_session/lib.rs.html#193-200" title="goto source code">[src]</a></h4><div class="docblock"><p>Adds the given key-value pairs to the session on the request.</p>
</div><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><h3 id="impl" class="impl"><code class="in-band">impl <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#147-295" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.get" class="method"><code>pub fn <a href="#method.get" class="fnname">get</a>&lt;T:&nbsp;<a class="trait" href="https://docs.rs/serde/1.0.125/serde/de/trait.DeserializeOwned.html" title="trait serde::de::DeserializeOwned">DeserializeOwned</a>&gt;(&amp;self, key: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;T&gt;, Error&gt;</code><a class="srclink" href="../src/actix_session/lib.rs.html#149-155" title="goto source code">[src]</a></h4><div class="docblock"><p>Get a <code>value</code> from the session.</p>
</div><h4 id="method.entries" class="method"><code>pub fn <a href="#method.entries" class="fnname">entries</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/cell/struct.Ref.html" title="struct core::cell::Ref">Ref</a>&lt;'_, <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;</code><a class="srclink" href="../src/actix_session/lib.rs.html#160-162" title="goto source code">[src]</a></h4><div class="docblock"><p>Get all raw key-value data from the session.</p>
<p>Note that values are JSON encoded.</p>
</div><h4 id="method.insert" class="method"><code>pub fn <a href="#method.insert" class="fnname">insert</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;key: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;value: impl <a class="trait" href="https://docs.rs/serde/1.0.125/serde/ser/trait.Serialize.html" title="trait serde::ser::Serialize">Serialize</a><br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error&gt;</code><a class="srclink" href="../src/actix_session/lib.rs.html#168-182" title="goto source code">[src]</a></h4><div class="docblock"><p>Inserts a key-value pair into the session.</p>
<p>Any serializable value can be used and will be encoded as JSON in session data, hence why
only a reference to the value is taken.</p>
</div><h4 id="method.remove" class="method"><code>pub fn <a href="#method.remove" class="fnname">remove</a>(&amp;self, key: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;</code><a class="srclink" href="../src/actix_session/lib.rs.html#187-196" title="goto source code">[src]</a></h4><div class="docblock"><p>Remove value from the session.</p>
<p>If present, the JSON encoded value is returned.</p>
</div><h4 id="method.remove_as" class="method"><code>pub fn <a href="#method.remove_as" class="fnname">remove_as</a>&lt;T:&nbsp;<a class="trait" href="https://docs.rs/serde/1.0.125/serde/de/trait.DeserializeOwned.html" title="trait serde::de::DeserializeOwned">DeserializeOwned</a>&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;key: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;</code><a class="srclink" href="../src/actix_session/lib.rs.html#202-218" title="goto source code">[src]</a></h4><div class="docblock"><p>Remove value from the session and deserialize.</p>
<p>Returns None if key was not present in session. Returns T if deserialization succeeds,
otherwise returns un-deserialized JSON string.</p>
</div><h4 id="method.clear" class="method"><code>pub fn <a href="#method.clear" class="fnname">clear</a>(&amp;self)</code><a class="srclink" href="../src/actix_session/lib.rs.html#221-228" title="goto source code">[src]</a></h4><div class="docblock"><p>Clear the session.</p>
</div><h4 id="method.purge" class="method"><code>pub fn <a href="#method.purge" class="fnname">purge</a>(&amp;self)</code><a class="srclink" href="../src/actix_session/lib.rs.html#231-235" title="goto source code">[src]</a></h4><div class="docblock"><p>Removes session both client and server side.</p>
</div><h4 id="method.renew" class="method"><code>pub fn <a href="#method.renew" class="fnname">renew</a>(&amp;self)</code><a class="srclink" href="../src/actix_session/lib.rs.html#238-244" title="goto source code">[src]</a></h4><div class="docblock"><p>Renews the session key, assigning existing session state to new key.</p>
</div><h4 id="method.set_session" class="method"><code>pub fn <a href="#method.set_session" class="fnname">set_session</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;req: &amp;mut ServiceRequest, <br>&nbsp;&nbsp;&nbsp;&nbsp;data: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>&lt;Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>&gt;<br>)</code><a class="srclink" href="../src/actix_session/lib.rs.html#262-269" title="goto source code">[src]</a></h4><div class="docblock"><p>Adds the given key-value pairs to the session on the request.</p>
<p>Values that match keys already existing on the session will be overwritten. Values should
already be JSON serialized.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
@ -33,28 +41,31 @@ already be JSON serialized.</p>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">req</span> <span class="op">=</span> <span class="ident">test</span>::<span class="ident">TestRequest</span>::<span class="ident">default</span>().<span class="ident">to_srv_request</span>();
<span class="ident">Session</span>::<span class="ident">set_session</span>(
<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">&quot;counter&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="number">0</span>).<span class="ident">unwrap</span>())],
<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">req</span>,
<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">&quot;counter&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="number">0</span>).<span class="ident">unwrap</span>())],
);</pre></div>
</div><h4 id="method.get_changes" class="method"><code>pub fn <a href="#method.get_changes" class="fnname">get_changes</a>&lt;B&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;res: &amp;mut ServiceResponse&lt;B&gt;<br>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a>, <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>&lt;Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>&gt;&gt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#202-219" title="goto source code">[src]</a></h4></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-FromRequest" class="impl"><code class="in-band">impl FromRequest for <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl-FromRequest" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#249-258" title="goto source code">[src]</a></h3><div class="docblock"><p>Extractor implementation for Session type.</p>
</div><h4 id="method.get_changes" class="method"><code>pub fn <a href="#method.get_changes" class="fnname">get_changes</a>&lt;B&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;res: &amp;mut ServiceResponse&lt;B&gt;<br>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="enum" href="../actix_session/enum.SessionStatus.html" title="enum actix_session::SessionStatus">SessionStatus</a>, impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>&lt;Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>&gt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#272-285" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns session status and iterator of key-value pairs of changes.</p>
</div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-FromRequest" class="impl"><code class="in-band">impl FromRequest for <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl-FromRequest" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#317-326" title="goto source code">[src]</a></h3><div class="docblock"><p>Extractor implementation for Session type.</p>
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">actix_session</span>::<span class="ident">Session</span>;
<span class="kw">fn</span> <span class="ident">index</span>(<span class="ident">session</span>: <span class="ident">Session</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> <span class="ident">str</span><span class="op">&gt;</span> {
<span class="attribute">#[<span class="ident">get</span>(<span class="string">&quot;/&quot;</span>)]</span>
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">index</span>(<span class="ident">session</span>: <span class="ident">Session</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="kw">impl</span> <span class="ident">Responder</span><span class="op">&gt;</span> {
<span class="comment">// access session data</span>
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">count</span>) <span class="op">=</span> <span class="ident">session</span>.<span class="ident">get</span>::<span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span>(<span class="string">&quot;counter&quot;</span>)<span class="question-mark">?</span> {
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="ident">count</span> <span class="op">+</span> <span class="number">1</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="ident">count</span> <span class="op">+</span> <span class="number">1</span>)<span class="question-mark">?</span>;
} <span class="kw">else</span> {
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">1</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">1</span>)<span class="question-mark">?</span>;
}
<span class="prelude-val">Ok</span>(<span class="string">&quot;Welcome!&quot;</span>)
<span class="kw">let</span> <span class="ident">count</span> <span class="op">=</span> <span class="ident">session</span>.<span class="ident">get</span>::<span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span>(<span class="string">&quot;counter&quot;</span>)<span class="question-mark">?</span>.<span class="ident">unwrap</span>();
<span class="prelude-val">Ok</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;Counter: {}&quot;</span>, <span class="ident">count</span>))
}</pre></div>
</div><div class="impl-items"><h4 id="associatedtype.Error" class="type"><code>type <a href="#associatedtype.Error" class="type">Error</a> = Error</code></h4><div class='docblock'><p>The associated error which can be returned.</p>
</div><h4 id="associatedtype.Future" class="type"><code>type <a href="#associatedtype.Future" class="type">Future</a> = Ready&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a>, Error&gt;&gt;</code></h4><div class='docblock'><p>Future that resolves to a Self.</p>
</div><h4 id="associatedtype.Config" class="type"><code>type <a href="#associatedtype.Config" class="type">Config</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a></code></h4><div class='docblock'><p>Configuration for this extractor.</p>
</div><h4 id="method.from_request" class="method hidden"><code>fn <a href="#method.from_request" class="fnname">from_request</a>(req: &amp;HttpRequest, _: &amp;mut Payload) -&gt; Self::Future</code><a class="srclink" href="../src/actix_session/lib.rs.html#255-257" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Create a Self from request parts asynchronously.</p>
</div><h4 id="method.from_request" class="method hidden"><code>fn <a href="#method.from_request" class="fnname">from_request</a>(req: &amp;HttpRequest, _: &amp;mut Payload) -&gt; Self::Future</code><a class="srclink" href="../src/actix_session/lib.rs.html#323-325" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Create a Self from request parts asynchronously.</p>
</div><h4 id="method.extract" class="method hidden"><code>pub fn <a href="#method.extract" class="fnname">extract</a>(req: &amp;HttpRequest) -&gt; Self::Future</code></h4><div class='docblock hidden'><p>Create a Self from request head asynchronously. <a href="#method.extract">Read more</a></p>
</div><h4 id="method.configure" class="method hidden"><code>pub fn <a href="#method.configure" class="fnname">configure</a>&lt;F&gt;(f: F) -&gt; Self::Config <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(Self::Config) -&gt; Self::Config,&nbsp;</span></code></h4><div class='docblock hidden'><p>Create and configure config instance.</p>
</div></div></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><h3 id="impl-RefUnwindSafe" class="impl"><code class="in-band">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl-RefUnwindSafe" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Send" class="impl"><code class="in-band">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl-Send" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Sync" class="impl"><code class="in-band">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl-Sync" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-Unpin" class="impl"><code class="in-band">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl-Unpin" class="anchor"></a></h3><div class="impl-items"></div><h3 id="impl-UnwindSafe" class="impl"><code class="in-band">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a href="#impl-UnwindSafe" class="anchor"></a></h3><div class="impl-items"></div></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><h3 id="impl-Any" class="impl"><code class="in-band">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code><a href="#impl-Any" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#131-135" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.type_id" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#132" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>

View File

@ -1,8 +1,9 @@
<!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="Extraction of a [`Session`] object."><meta name="keywords" content="rust, rustlang, rust-lang, UserSession"><title>actix_session::UserSession - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><script src="../crates.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">&#9776;</div><a href='../actix_session/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Trait UserSession</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.get_session">get_session</a></div><a class="sidebar-title" href="#foreign-impls">Implementations on Foreign Types</a><div class="sidebar-links"><a href="#impl-UserSession-for-HttpRequest">HttpRequest</a><a href="#impl-UserSession-for-RequestHead">RequestHead</a><a href="#impl-UserSession-for-ServiceRequest">ServiceRequest</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class="location"><a href="index.html">actix_session</a></p><div id="sidebar-vars" data-name="UserSession" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Trait <a href="index.html">actix_session</a>::<wbr><a class="trait" href="">UserSession</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/lib.rs.html#81-83" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait UserSession {
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Trait <a href="index.html">actix_session</a>::<wbr><a class="trait" href="">UserSession</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/actix_session/lib.rs.html#87-90" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust trait">pub trait UserSession {
fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a>;
}</pre></div><div class="docblock"><p>Extraction of a <a href="../actix_session/struct.Session.html" title="Session"><code>Session</code></a> object.</p>
</div><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.get_session" class="method"><code>fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#82" title="goto source code">[src]</a></h3></div><span class="loading-content">Loading content...</span><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><h3 id="impl-UserSession-for-HttpRequest" class="impl"><code class="in-band">impl <a class="trait" href="../actix_session/trait.UserSession.html" title="trait actix_session::UserSession">UserSession</a> for HttpRequest</code><a href="#impl-UserSession-for-HttpRequest" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#85-89" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.get_session" class="method hidden"><code>fn <a href="#method.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#86-88" title="goto source code">[src]</a></h4></div><h3 id="impl-UserSession-for-ServiceRequest" class="impl"><code class="in-band">impl <a class="trait" href="../actix_session/trait.UserSession.html" title="trait actix_session::UserSession">UserSession</a> for ServiceRequest</code><a href="#impl-UserSession-for-ServiceRequest" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#91-95" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.get_session-1" class="method hidden"><code>fn <a href="#method.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#92-94" title="goto source code">[src]</a></h4></div><h3 id="impl-UserSession-for-RequestHead" class="impl"><code class="in-band">impl <a class="trait" href="../actix_session/trait.UserSession.html" title="trait actix_session::UserSession">UserSession</a> for RequestHead</code><a href="#impl-UserSession-for-RequestHead" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#97-101" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.get_session-2" class="method hidden"><code>fn <a href="#method.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#98-100" title="goto source code">[src]</a></h4></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../implementors/actix_session/trait.UserSession.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="actix_session" data-search-js="../search-index.js"></div>
</div><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><h3 id="tymethod.get_session" class="method"><code>fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#89" title="goto source code">[src]</a></h3><div class="docblock"><p>Extract the <a href="../actix_session/struct.Session.html" title="Session"><code>Session</code></a> object</p>
</div></div><span class="loading-content">Loading content...</span><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><h3 id="impl-UserSession-for-HttpRequest" class="impl"><code class="in-band">impl <a class="trait" href="../actix_session/trait.UserSession.html" title="trait actix_session::UserSession">UserSession</a> for HttpRequest</code><a href="#impl-UserSession-for-HttpRequest" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#92-96" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.get_session" class="method hidden"><code>fn <a href="#method.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#93-95" title="goto source code">[src]</a></h4></div><h3 id="impl-UserSession-for-ServiceRequest" class="impl"><code class="in-band">impl <a class="trait" href="../actix_session/trait.UserSession.html" title="trait actix_session::UserSession">UserSession</a> for ServiceRequest</code><a href="#impl-UserSession-for-ServiceRequest" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#98-102" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.get_session-1" class="method hidden"><code>fn <a href="#method.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#99-101" title="goto source code">[src]</a></h4></div><h3 id="impl-UserSession-for-RequestHead" class="impl"><code class="in-band">impl <a class="trait" href="../actix_session/trait.UserSession.html" title="trait actix_session::UserSession">UserSession</a> for RequestHead</code><a href="#impl-UserSession-for-RequestHead" class="anchor"></a><a class="srclink" href="../src/actix_session/lib.rs.html#104-108" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.get_session-2" class="method hidden"><code>fn <a href="#method.get_session" class="fnname">get_session</a>(&amp;self) -&gt; <a class="struct" href="../actix_session/struct.Session.html" title="struct actix_session::Session">Session</a></code><a class="srclink" href="../src/actix_session/lib.rs.html#105-107" title="goto source code">[src]</a></h4></div><span class="loading-content">Loading content...</span><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"></div><span class="loading-content">Loading content...</span><script type="text/javascript" src="../implementors/actix_session/trait.UserSession.js" async></script></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="actix_session" data-search-js="../search-index.js"></div>
<script src="../main.js"></script></body></html>

File diff suppressed because one or more lines are too long

View File

@ -867,8 +867,9 @@
<span class="ident">Box</span>::<span class="ident">pin</span>(<span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="ident">state</span> <span class="op">=</span> <span class="ident">inner</span>.<span class="ident">load</span>(<span class="kw-2">&amp;</span><span class="ident">req</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let</span> <span class="ident">value</span> <span class="op">=</span> <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>((<span class="ident">state</span>, <span class="ident">value</span>)) <span class="op">=</span> <span class="ident">state</span> {
<span class="ident">Session</span>::<span class="ident">set_session</span>(<span class="ident">state</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">req</span>);
<span class="ident">Session</span>::<span class="ident">set_session</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">req</span>, <span class="ident">state</span>);
<span class="prelude-val">Some</span>(<span class="ident">value</span>)
} <span class="kw">else</span> {
<span class="prelude-val">None</span>
@ -877,8 +878,7 @@
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">res</span> <span class="op">=</span> <span class="ident">srv</span>.<span class="ident">call</span>(<span class="ident">req</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">match</span> <span class="ident">Session</span>::<span class="ident">get_changes</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">res</span>) {
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="prelude-val">None</span>) <span class="op">=</span><span class="op">&gt;</span> <span class="prelude-val">Ok</span>(<span class="ident">res</span>),
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="prelude-val">Some</span>(<span class="ident">state</span>)) <span class="op">=</span><span class="op">&gt;</span> {
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="ident">state</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">if</span> <span class="ident">value</span>.<span class="ident">is_none</span>() {
<span class="comment">// implies the session is new</span>
<span class="ident">inner</span>.<span class="ident">update</span>(<span class="ident">res</span>, <span class="ident">state</span>, <span class="ident">value</span>).<span class="kw">await</span>
@ -886,10 +886,10 @@
<span class="prelude-val">Ok</span>(<span class="ident">res</span>)
}
}
(<span class="ident">SessionStatus</span>::<span class="ident">Changed</span>, <span class="prelude-val">Some</span>(<span class="ident">state</span>)) <span class="op">=</span><span class="op">&gt;</span> {
<span class="ident">inner</span>.<span class="ident">update</span>(<span class="ident">res</span>, <span class="ident">state</span>, <span class="ident">value</span>).<span class="kw">await</span>
}
(<span class="ident">SessionStatus</span>::<span class="ident">Purged</span>, <span class="prelude-val">Some</span>(<span class="kw">_</span>)) <span class="op">=</span><span class="op">&gt;</span> {
(<span class="ident">SessionStatus</span>::<span class="ident">Changed</span>, <span class="ident">state</span>) <span class="op">=</span><span class="op">&gt;</span> <span class="ident">inner</span>.<span class="ident">update</span>(<span class="ident">res</span>, <span class="ident">state</span>, <span class="ident">value</span>).<span class="kw">await</span>,
(<span class="ident">SessionStatus</span>::<span class="ident">Purged</span>, <span class="kw">_</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">val</span>) <span class="op">=</span> <span class="ident">value</span> {
<span class="ident">inner</span>.<span class="ident">clear_cache</span>(<span class="ident">val</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">match</span> <span class="ident">inner</span>.<span class="ident">remove_cookie</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">res</span>) {
@ -900,7 +900,8 @@
<span class="prelude-val">Err</span>(<span class="ident">error</span>::<span class="ident">ErrorInternalServerError</span>(<span class="string">&quot;unexpected&quot;</span>))
}
}
(<span class="ident">SessionStatus</span>::<span class="ident">Renewed</span>, <span class="prelude-val">Some</span>(<span class="ident">state</span>)) <span class="op">=</span><span class="op">&gt;</span> {
(<span class="ident">SessionStatus</span>::<span class="ident">Renewed</span>, <span class="ident">state</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">val</span>) <span class="op">=</span> <span class="ident">value</span> {
<span class="ident">inner</span>.<span class="ident">clear_cache</span>(<span class="ident">val</span>).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="ident">inner</span>.<span class="ident">update</span>(<span class="ident">res</span>, <span class="ident">state</span>, <span class="prelude-val">None</span>).<span class="kw">await</span>
@ -908,7 +909,6 @@
<span class="ident">inner</span>.<span class="ident">update</span>(<span class="ident">res</span>, <span class="ident">state</span>, <span class="prelude-val">None</span>).<span class="kw">await</span>
}
}
(<span class="kw">_</span>, <span class="prelude-val">None</span>) <span class="op">=</span><span class="op">&gt;</span> <span class="macro">unreachable</span><span class="macro">!</span>(),
}
})
}
@ -1053,7 +1053,7 @@
<span class="prelude-val">Ok</span>(<span class="ident">res</span>)
}
<span class="doccomment">/// removes cache entry</span>
<span class="doccomment">/// Removes cache entry.</span>
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">clear_cache</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">key</span>: <span class="ident">String</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">Error</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="ident">cache_key</span> <span class="op">=</span> (<span class="self">self</span>.<span class="ident">cache_keygen</span>)(<span class="kw-2">&amp;</span><span class="ident">key</span>);
@ -1072,7 +1072,7 @@
}
}
<span class="doccomment">/// invalidates session cookie</span>
<span class="doccomment">/// Invalidates session cookie.</span>
<span class="kw">fn</span> <span class="ident">remove_cookie</span><span class="op">&lt;</span><span class="ident">B</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">res</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">ServiceResponse</span><span class="op">&lt;</span><span class="ident">B</span><span class="op">&gt;</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">Error</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">cookie</span> <span class="op">=</span> <span class="ident">Cookie</span>::<span class="ident">named</span>(<span class="self">self</span>.<span class="ident">name</span>.<span class="ident">clone</span>());
<span class="ident">cookie</span>.<span class="ident">set_value</span>(<span class="string">&quot;&quot;</span>);
@ -1121,7 +1121,7 @@
.<span class="ident">get</span>::<span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span>(<span class="string">&quot;counter&quot;</span>)
.<span class="ident">unwrap_or</span>(<span class="prelude-val">Some</span>(<span class="number">0</span>))
.<span class="ident">map_or</span>(<span class="number">1</span>, <span class="op">|</span><span class="ident">inner</span><span class="op">|</span> <span class="ident">inner</span> <span class="op">+</span> <span class="number">1</span>);
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="ident">counter</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">counter</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(<span class="ident">HttpResponse</span>::<span class="prelude-val">Ok</span>().<span class="ident">json</span>(<span class="kw-2">&amp;</span><span class="ident">IndexResponse</span> { <span class="ident">user_id</span>, <span class="ident">counter</span> }))
}
@ -1136,7 +1136,7 @@
<span class="ident">session</span>: <span class="ident">Session</span>,
) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">HttpResponse</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="ident">id</span> <span class="op">=</span> <span class="ident">user_id</span>.<span class="ident">into_inner</span>().<span class="ident">user_id</span>;
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;user_id&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">id</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;user_id&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">id</span>)<span class="question-mark">?</span>;
<span class="ident">session</span>.<span class="ident">renew</span>();
<span class="kw">let</span> <span class="ident">counter</span>: <span class="ident">i32</span> <span class="op">=</span> <span class="ident">session</span>

View File

@ -551,6 +551,8 @@
<span id="548">548</span>
<span id="549">549</span>
<span id="550">550</span>
<span id="551">551</span>
<span id="552">552</span>
</pre><div class="example-wrap"><pre class="rust ">
<span class="doccomment">//! Cookie based sessions. See docs for [`CookieSession`].</span>
@ -562,7 +564,7 @@
<span class="kw">use</span> <span class="ident">actix_web</span>::<span class="ident">http</span>::{<span class="ident">header</span>::<span class="ident">SET_COOKIE</span>, <span class="ident">HeaderValue</span>};
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">Error</span>, <span class="ident">HttpMessage</span>, <span class="ident">ResponseError</span>};
<span class="kw">use</span> <span class="ident">derive_more</span>::<span class="ident">Display</span>;
<span class="kw">use</span> <span class="ident">futures_util</span>::<span class="ident">future</span>::{<span class="ident">ok</span>, <span class="ident">FutureExt</span>, <span class="ident">LocalBoxFuture</span>, <span class="ident">Ready</span>};
<span class="kw">use</span> <span class="ident">futures_util</span>::<span class="ident">future</span>::{<span class="ident">ok</span>, <span class="ident">LocalBoxFuture</span>, <span class="ident">Ready</span>};
<span class="kw">use</span> <span class="ident">serde_json</span>::<span class="ident">error</span>::<span class="ident">Error</span> <span class="kw">as</span> <span class="ident">JsonError</span>;
<span class="kw">use</span> <span class="ident">time</span>::{<span class="ident">Duration</span>, <span class="ident">OffsetDateTime</span>};
@ -631,6 +633,7 @@
<span class="kw">let</span> <span class="ident">value</span> <span class="op">=</span>
<span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="ident">state</span>).<span class="ident">map_err</span>(<span class="ident">CookieSessionError</span>::<span class="ident">Serialize</span>)<span class="question-mark">?</span>;
<span class="kw">if</span> <span class="ident">value</span>.<span class="ident">len</span>() <span class="op">&gt;</span> <span class="number">4064</span> {
<span class="kw">return</span> <span class="prelude-val">Err</span>(<span class="ident">CookieSessionError</span>::<span class="ident">Overflow</span>.<span class="ident">into</span>());
}
@ -698,6 +701,7 @@
<span class="ident">jar</span>.<span class="ident">private</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">key</span>).<span class="ident">get</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">name</span>)
}
};
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">cookie</span>) <span class="op">=</span> <span class="ident">cookie_opt</span> {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Ok</span>(<span class="ident">val</span>) <span class="op">=</span> <span class="ident">serde_json</span>::<span class="ident">from_str</span>(<span class="ident">cookie</span>.<span class="ident">value</span>()) {
<span class="kw">return</span> (<span class="bool-val">false</span>, <span class="ident">val</span>);
@ -706,6 +710,7 @@
}
}
}
(<span class="bool-val">true</span>, <span class="ident">HashMap</span>::<span class="ident">new</span>())
}
}
@ -863,7 +868,7 @@
}
}
<span class="doccomment">/// Cookie session middleware</span>
<span class="doccomment">/// Cookie based session middleware.</span>
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">CookieSessionMiddleware</span><span class="op">&lt;</span><span class="ident">S</span><span class="op">&gt;</span> {
<span class="ident">service</span>: <span class="ident">S</span>,
<span class="ident">inner</span>: <span class="ident">Rc</span><span class="op">&lt;</span><span class="ident">CookieSessionInner</span><span class="op">&gt;</span>,
@ -890,42 +895,41 @@
<span class="kw">let</span> <span class="ident">inner</span> <span class="op">=</span> <span class="self">self</span>.<span class="ident">inner</span>.<span class="ident">clone</span>();
<span class="kw">let</span> (<span class="ident">is_new</span>, <span class="ident">state</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">inner</span>.<span class="ident">load</span>(<span class="kw-2">&amp;</span><span class="ident">req</span>);
<span class="kw">let</span> <span class="ident">prolong_expiration</span> <span class="op">=</span> <span class="self">self</span>.<span class="ident">inner</span>.<span class="ident">expires_in</span>.<span class="ident">is_some</span>();
<span class="ident">Session</span>::<span class="ident">set_session</span>(<span class="ident">state</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">req</span>);
<span class="ident">Session</span>::<span class="ident">set_session</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">req</span>, <span class="ident">state</span>);
<span class="kw">let</span> <span class="ident">fut</span> <span class="op">=</span> <span class="self">self</span>.<span class="ident">service</span>.<span class="ident">call</span>(<span class="ident">req</span>);
<span class="kw">async</span> <span class="kw">move</span> {
<span class="ident">fut</span>.<span class="kw">await</span>.<span class="ident">map</span>(<span class="op">|</span><span class="kw-2">mut</span> <span class="ident">res</span><span class="op">|</span> {
<span class="kw">match</span> <span class="ident">Session</span>::<span class="ident">get_changes</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">res</span>) {
(<span class="ident">SessionStatus</span>::<span class="ident">Changed</span>, <span class="prelude-val">Some</span>(<span class="ident">state</span>))
<span class="op">|</span> (<span class="ident">SessionStatus</span>::<span class="ident">Renewed</span>, <span class="prelude-val">Some</span>(<span class="ident">state</span>)) <span class="op">=</span><span class="op">&gt;</span> {
<span class="ident">Box</span>::<span class="ident">pin</span>(<span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">res</span> <span class="op">=</span> <span class="ident">fut</span>.<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let</span> <span class="ident">res</span> <span class="op">=</span> <span class="kw">match</span> <span class="ident">Session</span>::<span class="ident">get_changes</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">res</span>) {
(<span class="ident">SessionStatus</span>::<span class="ident">Changed</span>, <span class="ident">state</span>) <span class="op">|</span> (<span class="ident">SessionStatus</span>::<span class="ident">Renewed</span>, <span class="ident">state</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="ident">res</span>.<span class="ident">checked_expr</span>(<span class="op">|</span><span class="ident">res</span><span class="op">|</span> <span class="ident">inner</span>.<span class="ident">set_cookie</span>(<span class="ident">res</span>, <span class="ident">state</span>))
}
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="prelude-val">Some</span>(<span class="ident">state</span>)) <span class="kw">if</span> <span class="ident">prolong_expiration</span> <span class="op">=</span><span class="op">&gt;</span> {
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="ident">state</span>) <span class="kw">if</span> <span class="ident">prolong_expiration</span> <span class="op">=</span><span class="op">&gt;</span> {
<span class="ident">res</span>.<span class="ident">checked_expr</span>(<span class="op">|</span><span class="ident">res</span><span class="op">|</span> <span class="ident">inner</span>.<span class="ident">set_cookie</span>(<span class="ident">res</span>, <span class="ident">state</span>))
}
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="kw">_</span>) <span class="op">=</span><span class="op">&gt;</span>
<span class="comment">// set a new session cookie upon first request (new client)</span>
{
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="kw">_</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">if</span> <span class="ident">is_new</span> {
<span class="kw">let</span> <span class="ident">state</span>: <span class="ident">HashMap</span><span class="op">&lt;</span><span class="ident">String</span>, <span class="ident">String</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
<span class="ident">res</span>.<span class="ident">checked_expr</span>(<span class="op">|</span><span class="ident">res</span><span class="op">|</span> {
<span class="ident">inner</span>.<span class="ident">set_cookie</span>(<span class="ident">res</span>, <span class="ident">state</span>.<span class="ident">into_iter</span>())
})
<span class="ident">res</span>.<span class="ident">checked_expr</span>(<span class="op">|</span><span class="ident">res</span><span class="op">|</span> <span class="ident">inner</span>.<span class="ident">set_cookie</span>(<span class="ident">res</span>, <span class="ident">state</span>.<span class="ident">into_iter</span>()))
} <span class="kw">else</span> {
<span class="ident">res</span>
}
}
(<span class="ident">SessionStatus</span>::<span class="ident">Purged</span>, <span class="kw">_</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">inner</span>.<span class="ident">remove_cookie</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">res</span>);
<span class="ident">res</span>
}
<span class="kw">_</span> <span class="op">=</span><span class="op">&gt;</span> <span class="ident">res</span>,
}
};
<span class="prelude-val">Ok</span>(<span class="ident">res</span>)
})
}
.<span class="ident">boxed_local</span>()
}
}
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">test</span>)]</span>
@ -940,7 +944,7 @@
<span class="ident">App</span>::<span class="ident">new</span>()
.<span class="ident">wrap</span>(<span class="ident">CookieSession</span>::<span class="ident">signed</span>(<span class="kw-2">&amp;</span>[<span class="number">0</span>; <span class="number">32</span>]).<span class="ident">secure</span>(<span class="bool-val">false</span>))
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="ident">ses</span>: <span class="ident">Session</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="string">&quot;test&quot;</span>
})),
)
@ -960,7 +964,7 @@
<span class="ident">App</span>::<span class="ident">new</span>()
.<span class="ident">wrap</span>(<span class="ident">CookieSession</span>::<span class="ident">private</span>(<span class="kw-2">&amp;</span>[<span class="number">0</span>; <span class="number">32</span>]).<span class="ident">secure</span>(<span class="bool-val">false</span>))
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="ident">ses</span>: <span class="ident">Session</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="string">&quot;test&quot;</span>
})),
)
@ -980,7 +984,7 @@
<span class="ident">App</span>::<span class="ident">new</span>()
.<span class="ident">wrap</span>(<span class="ident">CookieSession</span>::<span class="ident">signed</span>(<span class="kw-2">&amp;</span>[<span class="number">0</span>; <span class="number">32</span>]).<span class="ident">secure</span>(<span class="bool-val">false</span>).<span class="ident">lazy</span>(<span class="bool-val">true</span>))
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/count&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="ident">ses</span>: <span class="ident">Session</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="string">&quot;counting&quot;</span>
}))
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="ident">_ses</span>: <span class="ident">Session</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> { <span class="string">&quot;test&quot;</span> })),
@ -1006,7 +1010,7 @@
<span class="ident">App</span>::<span class="ident">new</span>()
.<span class="ident">wrap</span>(<span class="ident">CookieSession</span>::<span class="ident">signed</span>(<span class="kw-2">&amp;</span>[<span class="number">0</span>; <span class="number">32</span>]).<span class="ident">secure</span>(<span class="bool-val">false</span>))
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="ident">ses</span>: <span class="ident">Session</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="string">&quot;test&quot;</span>
})),
)
@ -1034,7 +1038,7 @@
.<span class="ident">max_age</span>(<span class="number">100</span>),
)
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="ident">ses</span>: <span class="ident">Session</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="string">&quot;test&quot;</span>
}))
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/test/&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="ident">ses</span>: <span class="ident">Session</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
@ -1067,7 +1071,7 @@
<span class="ident">App</span>::<span class="ident">new</span>()
.<span class="ident">wrap</span>(<span class="ident">CookieSession</span>::<span class="ident">signed</span>(<span class="kw-2">&amp;</span>[<span class="number">0</span>; <span class="number">32</span>]).<span class="ident">secure</span>(<span class="bool-val">false</span>).<span class="ident">expires_in</span>(<span class="number">60</span>))
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="ident">ses</span>: <span class="ident">Session</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">set</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="ident">ses</span>.<span class="ident">insert</span>(<span class="string">&quot;counter&quot;</span>, <span class="number">100</span>);
<span class="string">&quot;test&quot;</span>
}))
.<span class="ident">service</span>(

View File

@ -333,6 +333,85 @@
<span id="330">330</span>
<span id="331">331</span>
<span id="332">332</span>
<span id="333">333</span>
<span id="334">334</span>
<span id="335">335</span>
<span id="336">336</span>
<span id="337">337</span>
<span id="338">338</span>
<span id="339">339</span>
<span id="340">340</span>
<span id="341">341</span>
<span id="342">342</span>
<span id="343">343</span>
<span id="344">344</span>
<span id="345">345</span>
<span id="346">346</span>
<span id="347">347</span>
<span id="348">348</span>
<span id="349">349</span>
<span id="350">350</span>
<span id="351">351</span>
<span id="352">352</span>
<span id="353">353</span>
<span id="354">354</span>
<span id="355">355</span>
<span id="356">356</span>
<span id="357">357</span>
<span id="358">358</span>
<span id="359">359</span>
<span id="360">360</span>
<span id="361">361</span>
<span id="362">362</span>
<span id="363">363</span>
<span id="364">364</span>
<span id="365">365</span>
<span id="366">366</span>
<span id="367">367</span>
<span id="368">368</span>
<span id="369">369</span>
<span id="370">370</span>
<span id="371">371</span>
<span id="372">372</span>
<span id="373">373</span>
<span id="374">374</span>
<span id="375">375</span>
<span id="376">376</span>
<span id="377">377</span>
<span id="378">378</span>
<span id="379">379</span>
<span id="380">380</span>
<span id="381">381</span>
<span id="382">382</span>
<span id="383">383</span>
<span id="384">384</span>
<span id="385">385</span>
<span id="386">386</span>
<span id="387">387</span>
<span id="388">388</span>
<span id="389">389</span>
<span id="390">390</span>
<span id="391">391</span>
<span id="392">392</span>
<span id="393">393</span>
<span id="394">394</span>
<span id="395">395</span>
<span id="396">396</span>
<span id="397">397</span>
<span id="398">398</span>
<span id="399">399</span>
<span id="400">400</span>
<span id="401">401</span>
<span id="402">402</span>
<span id="403">403</span>
<span id="404">404</span>
<span id="405">405</span>
<span id="406">406</span>
<span id="407">407</span>
<span id="408">408</span>
<span id="409">409</span>
<span id="410">410</span>
<span id="411">411</span>
</pre><div class="example-wrap"><pre class="rust ">
<span class="doccomment">//! Sessions for Actix Web.</span>
<span class="doccomment">//!</span>
@ -354,9 +433,9 @@
<span class="doccomment">//! // access session data</span>
<span class="doccomment">//! if let Some(count) = session.get::&lt;i32&gt;(&quot;counter&quot;)? {</span>
<span class="doccomment">//! println!(&quot;SESSION value: {}&quot;, count);</span>
<span class="doccomment">//! session.set(&quot;counter&quot;, count + 1)?;</span>
<span class="doccomment">//! session.insert(&quot;counter&quot;, count + 1)?;</span>
<span class="doccomment">//! } else {</span>
<span class="doccomment">//! session.set(&quot;counter&quot;, 1)?;</span>
<span class="doccomment">//! session.insert(&quot;counter&quot;, 1)?;</span>
<span class="doccomment">//! }</span>
<span class="doccomment">//!</span>
<span class="doccomment">//! Ok(&quot;Welcome!&quot;)</span>
@ -375,21 +454,27 @@
<span class="doccomment">//! }</span>
<span class="doccomment">//! ```</span>
<span class="attribute">#![<span class="ident">deny</span>(<span class="ident">rust_2018_idioms</span>)]</span>
<span class="attribute">#![<span class="ident">deny</span>(<span class="ident">rust_2018_idioms</span>, <span class="ident">nonstandard_style</span>)]</span>
<span class="attribute">#![<span class="ident">warn</span>(<span class="ident">missing_docs</span>)]</span>
<span class="kw">use</span> <span class="ident">std</span>::{<span class="ident">cell</span>::<span class="ident">RefCell</span>, <span class="ident">collections</span>::<span class="ident">HashMap</span>, <span class="ident">rc</span>::<span class="ident">Rc</span>};
<span class="kw">use</span> <span class="ident">actix_web</span>::<span class="ident">dev</span>::{
<span class="ident">Extensions</span>, <span class="ident">Payload</span>, <span class="ident">RequestHead</span>, <span class="ident">ServiceRequest</span>, <span class="ident">ServiceResponse</span>,
<span class="kw">use</span> <span class="ident">std</span>::{
<span class="ident">cell</span>::{<span class="ident">Ref</span>, <span class="ident">RefCell</span>},
<span class="ident">collections</span>::<span class="ident">HashMap</span>,
<span class="ident">mem</span>,
<span class="ident">rc</span>::<span class="ident">Rc</span>,
};
<span class="kw">use</span> <span class="ident">actix_web</span>::{
<span class="ident">dev</span>::{<span class="ident">Extensions</span>, <span class="ident">Payload</span>, <span class="ident">RequestHead</span>, <span class="ident">ServiceRequest</span>, <span class="ident">ServiceResponse</span>},
<span class="ident">Error</span>, <span class="ident">FromRequest</span>, <span class="ident">HttpMessage</span>, <span class="ident">HttpRequest</span>,
};
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">Error</span>, <span class="ident">FromRequest</span>, <span class="ident">HttpMessage</span>, <span class="ident">HttpRequest</span>};
<span class="kw">use</span> <span class="ident">futures_util</span>::<span class="ident">future</span>::{<span class="ident">ok</span>, <span class="ident">Ready</span>};
<span class="kw">use</span> <span class="ident">serde</span>::{<span class="ident">de</span>::<span class="ident">DeserializeOwned</span>, <span class="ident">Serialize</span>};
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">feature</span> <span class="op">=</span> <span class="string">&quot;cookie-session&quot;</span>)]</span>
<span class="kw">mod</span> <span class="ident">cookie</span>;
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">feature</span> <span class="op">=</span> <span class="string">&quot;cookie-session&quot;</span>)]</span>
<span class="kw">pub</span> <span class="kw">use</span> <span class="kw">crate</span>::<span class="ident">cookie</span>::<span class="ident">CookieSession</span>;
<span class="kw">pub</span> <span class="kw">use</span> <span class="self">self</span>::<span class="ident">cookie</span>::<span class="ident">CookieSession</span>;
<span class="doccomment">/// The high-level interface you use to modify session data.</span>
<span class="doccomment">///</span>
@ -403,9 +488,9 @@
<span class="doccomment">/// async fn index(session: Session) -&gt; Result&lt;&amp;&#39;static str&gt; {</span>
<span class="doccomment">/// // access session data</span>
<span class="doccomment">/// if let Some(count) = session.get::&lt;i32&gt;(&quot;counter&quot;)? {</span>
<span class="doccomment">/// session.set(&quot;counter&quot;, count + 1)?;</span>
<span class="doccomment">/// session.insert(&quot;counter&quot;, count + 1)?;</span>
<span class="doccomment">/// } else {</span>
<span class="doccomment">/// session.set(&quot;counter&quot;, 1)?;</span>
<span class="doccomment">/// session.insert(&quot;counter&quot;, 1)?;</span>
<span class="doccomment">/// }</span>
<span class="doccomment">///</span>
<span class="doccomment">/// Ok(&quot;Welcome!&quot;)</span>
@ -415,6 +500,7 @@
<span class="doccomment">/// Extraction of a [`Session`] object.</span>
<span class="kw">pub</span> <span class="kw">trait</span> <span class="ident">UserSession</span> {
<span class="doccomment">/// Extract the [`Session`] object</span>
<span class="kw">fn</span> <span class="ident">get_session</span>(<span class="kw-2">&amp;</span><span class="self">self</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">Session</span>;
}
@ -436,13 +522,31 @@
}
}
<span class="doccomment">/// Status of a [`Session`].</span>
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">PartialEq</span>, <span class="ident">Clone</span>, <span class="ident">Debug</span>)]</span>
<span class="kw">pub</span> <span class="kw">enum</span> <span class="ident">SessionStatus</span> {
<span class="doccomment">/// Session has been updated and requires a new persist operation.</span>
<span class="ident">Changed</span>,
<span class="doccomment">/// Session is flagged for deletion and should be removed from client and server.</span>
<span class="doccomment">///</span>
<span class="doccomment">/// Most operations on the session after purge flag is set should have no effect.</span>
<span class="ident">Purged</span>,
<span class="doccomment">/// Session is flagged for refresh.</span>
<span class="doccomment">///</span>
<span class="doccomment">/// For example, when using a backend that has a TTL (time-to-live) expiry on the session entry,</span>
<span class="doccomment">/// the session will be refreshed even if no data inside it has changed. The client may also</span>
<span class="doccomment">/// be notified of the refresh.</span>
<span class="ident">Renewed</span>,
<span class="doccomment">/// Session is unchanged from when last seen (if exists).</span>
<span class="doccomment">///</span>
<span class="doccomment">/// This state also captures new (previously unissued) sessions such as a user&#39;s first</span>
<span class="doccomment">/// site visit.</span>
<span class="ident">Unchanged</span>,
}
<span class="kw">impl</span> <span class="ident">Default</span> <span class="kw">for</span> <span class="ident">SessionStatus</span> {
<span class="kw">fn</span> <span class="ident">default</span>() <span class="op">-</span><span class="op">&gt;</span> <span class="ident">SessionStatus</span> {
<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>
@ -452,7 +556,7 @@
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Default</span>)]</span>
<span class="kw">struct</span> <span class="ident">SessionInner</span> {
<span class="ident">state</span>: <span class="ident">HashMap</span><span class="op">&lt;</span><span class="ident">String</span>, <span class="ident">String</span><span class="op">&gt;</span>,
<span class="kw">pub</span> <span class="ident">status</span>: <span class="ident">SessionStatus</span>,
<span class="ident">status</span>: <span class="ident">SessionStatus</span>,
}
<span class="kw">impl</span> <span class="ident">Session</span> {
@ -465,37 +569,80 @@
}
}
<span class="doccomment">/// Set a `value` from the session.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">set</span><span class="op">&lt;</span><span class="ident">T</span>: <span class="ident">Serialize</span><span class="op">&gt;</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">key</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>, <span class="ident">value</span>: <span class="ident">T</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">Error</span><span class="op">&gt;</span> {
<span class="doccomment">/// Get all raw key-value data from the session.</span>
<span class="doccomment">///</span>
<span class="doccomment">/// Note that values are JSON encoded.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">entries</span>(<span class="kw-2">&amp;</span><span class="self">self</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="ident">Ref</span><span class="op">&lt;</span><span class="lifetime">&#39;_</span>, <span class="ident">HashMap</span><span class="op">&lt;</span><span class="ident">String</span>, <span class="ident">String</span><span class="op">&gt;</span><span class="op">&gt;</span> {
<span class="ident">Ref</span>::<span class="ident">map</span>(<span class="self">self</span>.<span class="number">0</span>.<span class="ident">borrow</span>(), <span class="op">|</span><span class="ident">inner</span><span class="op">|</span> <span class="kw-2">&amp;</span><span class="ident">inner</span>.<span class="ident">state</span>)
}
<span class="doccomment">/// Inserts a key-value pair into the session.</span>
<span class="doccomment">///</span>
<span class="doccomment">/// Any serializable value can be used and will be encoded as JSON in session data, hence why</span>
<span class="doccomment">/// only a reference to the value is taken.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">insert</span>(
<span class="kw-2">&amp;</span><span class="self">self</span>,
<span class="ident">key</span>: <span class="kw">impl</span> <span class="ident">Into</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span>,
<span class="ident">value</span>: <span class="kw">impl</span> <span class="ident">Serialize</span>,
) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">Error</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">inner</span> <span class="op">=</span> <span class="self">self</span>.<span class="number">0</span>.<span class="ident">borrow_mut</span>();
<span class="kw">if</span> <span class="ident">inner</span>.<span class="ident">status</span> <span class="op">!</span><span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Purged</span> {
<span class="ident">inner</span>.<span class="ident">status</span> <span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Changed</span>;
<span class="ident">inner</span>
.<span class="ident">state</span>
.<span class="ident">insert</span>(<span class="ident">key</span>.<span class="ident">to_owned</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="ident">value</span>)<span class="question-mark">?</span>);
<span class="kw">let</span> <span class="ident">val</span> <span class="op">=</span> <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="ident">value</span>)<span class="question-mark">?</span>;
<span class="ident">inner</span>.<span class="ident">state</span>.<span class="ident">insert</span>(<span class="ident">key</span>.<span class="ident">into</span>(), <span class="ident">val</span>);
}
<span class="prelude-val">Ok</span>(())
}
<span class="doccomment">/// Remove value from the session.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">remove</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">key</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>) {
<span class="doccomment">///</span>
<span class="doccomment">/// If present, the JSON encoded value is returned.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">remove</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">key</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">inner</span> <span class="op">=</span> <span class="self">self</span>.<span class="number">0</span>.<span class="ident">borrow_mut</span>();
<span class="kw">if</span> <span class="ident">inner</span>.<span class="ident">status</span> <span class="op">!</span><span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Purged</span> {
<span class="ident">inner</span>.<span class="ident">status</span> <span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Changed</span>;
<span class="ident">inner</span>.<span class="ident">state</span>.<span class="ident">remove</span>(<span class="ident">key</span>);
<span class="kw">return</span> <span class="ident">inner</span>.<span class="ident">state</span>.<span class="ident">remove</span>(<span class="ident">key</span>);
}
<span class="prelude-val">None</span>
}
<span class="doccomment">/// Remove value from the session and deserialize.</span>
<span class="doccomment">///</span>
<span class="doccomment">/// Returns None if key was not present in session. Returns T if deserialization succeeds,</span>
<span class="doccomment">/// otherwise returns un-deserialized JSON string.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">remove_as</span><span class="op">&lt;</span><span class="ident">T</span>: <span class="ident">DeserializeOwned</span><span class="op">&gt;</span>(
<span class="kw-2">&amp;</span><span class="self">self</span>,
<span class="ident">key</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>,
) <span class="op">-</span><span class="op">&gt;</span> <span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="prelude-ty">Result</span><span class="op">&lt;</span><span class="ident">T</span>, <span class="ident">String</span><span class="op">&gt;</span><span class="op">&gt;</span> {
<span class="self">self</span>.<span class="ident">remove</span>(<span class="ident">key</span>)
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">val_str</span><span class="op">|</span> <span class="kw">match</span> <span class="ident">serde_json</span>::<span class="ident">from_str</span>(<span class="kw-2">&amp;</span><span class="ident">val_str</span>) {
<span class="prelude-val">Ok</span>(<span class="ident">val</span>) <span class="op">=</span><span class="op">&gt;</span> <span class="prelude-val">Ok</span>(<span class="ident">val</span>),
<span class="prelude-val">Err</span>(<span class="ident">_err</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="ident">log</span>::<span class="macro">debug</span><span class="macro">!</span>(
<span class="string">&quot;removed value (key: {}) could not be deserialized as {}&quot;</span>,
<span class="ident">key</span>,
<span class="ident">std</span>::<span class="ident">any</span>::<span class="ident">type_name</span>::<span class="op">&lt;</span><span class="ident">T</span><span class="op">&gt;</span>()
);
<span class="prelude-val">Err</span>(<span class="ident">val_str</span>)
}
})
}
<span class="doccomment">/// Clear the session.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">clear</span>(<span class="kw-2">&amp;</span><span class="self">self</span>) {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">inner</span> <span class="op">=</span> <span class="self">self</span>.<span class="number">0</span>.<span class="ident">borrow_mut</span>();
<span class="kw">if</span> <span class="ident">inner</span>.<span class="ident">status</span> <span class="op">!</span><span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Purged</span> {
<span class="ident">inner</span>.<span class="ident">status</span> <span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Changed</span>;
<span class="ident">inner</span>.<span class="ident">state</span>.<span class="ident">clear</span>()
}
}
<span class="doccomment">/// Removes session, both client and server side.</span>
<span class="doccomment">/// Removes session both client and server side.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">purge</span>(<span class="kw-2">&amp;</span><span class="self">self</span>) {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">inner</span> <span class="op">=</span> <span class="self">self</span>.<span class="number">0</span>.<span class="ident">borrow_mut</span>();
<span class="ident">inner</span>.<span class="ident">status</span> <span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Purged</span>;
@ -505,6 +652,7 @@
<span class="doccomment">/// Renews the session key, assigning existing session state to new key.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">renew</span>(<span class="kw-2">&amp;</span><span class="self">self</span>) {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">inner</span> <span class="op">=</span> <span class="self">self</span>.<span class="number">0</span>.<span class="ident">borrow_mut</span>();
<span class="kw">if</span> <span class="ident">inner</span>.<span class="ident">status</span> <span class="op">!</span><span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Purged</span> {
<span class="ident">inner</span>.<span class="ident">status</span> <span class="op">=</span> <span class="ident">SessionStatus</span>::<span class="ident">Renewed</span>;
}
@ -522,35 +670,32 @@
<span class="doccomment">/// let mut req = test::TestRequest::default().to_srv_request();</span>
<span class="doccomment">///</span>
<span class="doccomment">/// Session::set_session(</span>
<span class="doccomment">/// vec![(&quot;counter&quot;.to_string(), serde_json::to_string(&amp;0).unwrap())],</span>
<span class="doccomment">/// &amp;mut req,</span>
<span class="doccomment">/// vec![(&quot;counter&quot;.to_string(), serde_json::to_string(&amp;0).unwrap())],</span>
<span class="doccomment">/// );</span>
<span class="doccomment">/// ```</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">set_session</span>(
<span class="ident">data</span>: <span class="kw">impl</span> <span class="ident">IntoIterator</span><span class="op">&lt;</span><span class="ident">Item</span> <span class="op">=</span> (<span class="ident">String</span>, <span class="ident">String</span>)<span class="op">&gt;</span>,
<span class="ident">req</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">ServiceRequest</span>,
<span class="ident">data</span>: <span class="kw">impl</span> <span class="ident">IntoIterator</span><span class="op">&lt;</span><span class="ident">Item</span> <span class="op">=</span> (<span class="ident">String</span>, <span class="ident">String</span>)<span class="op">&gt;</span>,
) {
<span class="kw">let</span> <span class="ident">session</span> <span class="op">=</span> <span class="ident">Session</span>::<span class="ident">get_session</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="kw-2">*</span><span class="ident">req</span>.<span class="ident">extensions_mut</span>());
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">inner</span> <span class="op">=</span> <span class="ident">session</span>.<span class="number">0</span>.<span class="ident">borrow_mut</span>();
<span class="ident">inner</span>.<span class="ident">state</span>.<span class="ident">extend</span>(<span class="ident">data</span>);
}
<span class="doccomment">/// Returns session status and iterator of key-value pairs of changes.</span>
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_changes</span><span class="op">&lt;</span><span class="ident">B</span><span class="op">&gt;</span>(
<span class="ident">res</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">ServiceResponse</span><span class="op">&lt;</span><span class="ident">B</span><span class="op">&gt;</span>,
) <span class="op">-</span><span class="op">&gt;</span> (
<span class="ident">SessionStatus</span>,
<span class="prelude-ty">Option</span><span class="op">&lt;</span><span class="kw">impl</span> <span class="ident">Iterator</span><span class="op">&lt;</span><span class="ident">Item</span> <span class="op">=</span> (<span class="ident">String</span>, <span class="ident">String</span>)<span class="op">&gt;</span><span class="op">&gt;</span>,
) {
) <span class="op">-</span><span class="op">&gt;</span> (<span class="ident">SessionStatus</span>, <span class="kw">impl</span> <span class="ident">Iterator</span><span class="op">&lt;</span><span class="ident">Item</span> <span class="op">=</span> (<span class="ident">String</span>, <span class="ident">String</span>)<span class="op">&gt;</span>) {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">s_impl</span>) <span class="op">=</span> <span class="ident">res</span>
.<span class="ident">request</span>()
.<span class="ident">extensions</span>()
.<span class="ident">get</span>::<span class="op">&lt;</span><span class="ident">Rc</span><span class="op">&lt;</span><span class="ident">RefCell</span><span class="op">&lt;</span><span class="ident">SessionInner</span><span class="op">&gt;</span><span class="op">&gt;</span><span class="op">&gt;</span>()
{
<span class="kw">let</span> <span class="ident">state</span> <span class="op">=</span>
<span class="ident">std</span>::<span class="ident">mem</span>::<span class="ident">replace</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">s_impl</span>.<span class="ident">borrow_mut</span>().<span class="ident">state</span>, <span class="ident">HashMap</span>::<span class="ident">new</span>());
(<span class="ident">s_impl</span>.<span class="ident">borrow</span>().<span class="ident">status</span>.<span class="ident">clone</span>(), <span class="prelude-val">Some</span>(<span class="ident">state</span>.<span class="ident">into_iter</span>()))
<span class="kw">let</span> <span class="ident">state</span> <span class="op">=</span> <span class="ident">mem</span>::<span class="ident">take</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">s_impl</span>.<span class="ident">borrow_mut</span>().<span class="ident">state</span>);
(<span class="ident">s_impl</span>.<span class="ident">borrow</span>().<span class="ident">status</span>.<span class="ident">clone</span>(), <span class="ident">state</span>.<span class="ident">into_iter</span>())
} <span class="kw">else</span> {
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="prelude-val">None</span>)
(<span class="ident">SessionStatus</span>::<span class="ident">Unchanged</span>, <span class="ident">HashMap</span>::<span class="ident">new</span>().<span class="ident">into_iter</span>())
}
}
@ -566,21 +711,23 @@
<span class="doccomment">/// Extractor implementation for Session type.</span>
<span class="doccomment">///</span>
<span class="doccomment">/// ```rust</span>
<span class="doccomment">/// # Examples</span>
<span class="doccomment">/// ```</span>
<span class="doccomment">/// # use actix_web::*;</span>
<span class="doccomment">/// use actix_session::Session;</span>
<span class="doccomment">///</span>
<span class="doccomment">/// fn index(session: Session) -&gt; Result&lt;&amp;&#39;static str&gt; {</span>
<span class="doccomment">/// #[get(&quot;/&quot;)]</span>
<span class="doccomment">/// async fn index(session: Session) -&gt; Result&lt;impl Responder&gt; {</span>
<span class="doccomment">/// // access session data</span>
<span class="doccomment">/// if let Some(count) = session.get::&lt;i32&gt;(&quot;counter&quot;)? {</span>
<span class="doccomment">/// session.set(&quot;counter&quot;, count + 1)?;</span>
<span class="doccomment">/// session.insert(&quot;counter&quot;, count + 1)?;</span>
<span class="doccomment">/// } else {</span>
<span class="doccomment">/// session.set(&quot;counter&quot;, 1)?;</span>
<span class="doccomment">/// session.insert(&quot;counter&quot;, 1)?;</span>
<span class="doccomment">/// }</span>
<span class="doccomment">///</span>
<span class="doccomment">/// Ok(&quot;Welcome!&quot;)</span>
<span class="doccomment">/// let count = session.get::&lt;i32&gt;(&quot;counter&quot;)?.unwrap();</span>
<span class="doccomment">/// Ok(format!(&quot;Counter: {}&quot;, count))</span>
<span class="doccomment">/// }</span>
<span class="doccomment">/// # fn main() {}</span>
<span class="doccomment">/// ```</span>
<span class="kw">impl</span> <span class="ident">FromRequest</span> <span class="kw">for</span> <span class="ident">Session</span> {
<span class="kw">type</span> <span class="ident">Error</span> <span class="op">=</span> <span class="ident">Error</span>;
@ -604,19 +751,19 @@
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">req</span> <span class="op">=</span> <span class="ident">test</span>::<span class="ident">TestRequest</span>::<span class="ident">default</span>().<span class="ident">to_srv_request</span>();
<span class="ident">Session</span>::<span class="ident">set_session</span>(
<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">&quot;key&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="string">&quot;value&quot;</span>).<span class="ident">unwrap</span>())],
<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">req</span>,
<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">&quot;key&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="string">&quot;value&quot;</span>).<span class="ident">unwrap</span>())],
);
<span class="kw">let</span> <span class="ident">session</span> <span class="op">=</span> <span class="ident">Session</span>::<span class="ident">get_session</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="kw-2">*</span><span class="ident">req</span>.<span class="ident">extensions_mut</span>());
<span class="kw">let</span> <span class="ident">res</span> <span class="op">=</span> <span class="ident">session</span>.<span class="ident">get</span>::<span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span>(<span class="string">&quot;key&quot;</span>).<span class="ident">unwrap</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">res</span>, <span class="prelude-val">Some</span>(<span class="string">&quot;value&quot;</span>.<span class="ident">to_string</span>()));
<span class="ident">session</span>.<span class="ident">set</span>(<span class="string">&quot;key2&quot;</span>, <span class="string">&quot;value2&quot;</span>.<span class="ident">to_string</span>()).<span class="ident">unwrap</span>();
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;key2&quot;</span>, <span class="string">&quot;value2&quot;</span>).<span class="ident">unwrap</span>();
<span class="ident">session</span>.<span class="ident">remove</span>(<span class="string">&quot;key&quot;</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">res</span> <span class="op">=</span> <span class="ident">req</span>.<span class="ident">into_response</span>(<span class="ident">HttpResponse</span>::<span class="prelude-val">Ok</span>().<span class="ident">finish</span>());
<span class="kw">let</span> (<span class="ident">_status</span>, <span class="ident">state</span>) <span class="op">=</span> <span class="ident">Session</span>::<span class="ident">get_changes</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">res</span>);
<span class="kw">let</span> <span class="ident">changes</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">state</span>.<span class="ident">unwrap</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">changes</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">state</span>.<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">changes</span>, [(<span class="string">&quot;key2&quot;</span>.<span class="ident">to_string</span>(), <span class="string">&quot;\&quot;value2\&quot;&quot;</span>.<span class="ident">to_string</span>())]);
}
@ -625,8 +772,8 @@
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">req</span> <span class="op">=</span> <span class="ident">test</span>::<span class="ident">TestRequest</span>::<span class="ident">default</span>().<span class="ident">to_srv_request</span>();
<span class="ident">Session</span>::<span class="ident">set_session</span>(
<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">&quot;key&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="bool-val">true</span>).<span class="ident">unwrap</span>())],
<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">req</span>,
<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">&quot;key&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="bool-val">true</span>).<span class="ident">unwrap</span>())],
);
<span class="kw">let</span> <span class="ident">session</span> <span class="op">=</span> <span class="ident">req</span>.<span class="ident">get_session</span>();
@ -639,8 +786,8 @@
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">req</span> <span class="op">=</span> <span class="ident">test</span>::<span class="ident">TestRequest</span>::<span class="ident">default</span>().<span class="ident">to_srv_request</span>();
<span class="ident">Session</span>::<span class="ident">set_session</span>(
<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">&quot;key&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="number">10</span>).<span class="ident">unwrap</span>())],
<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">req</span>,
<span class="macro">vec</span><span class="macro">!</span>[(<span class="string">&quot;key&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">serde_json</span>::<span class="ident">to_string</span>(<span class="kw-2">&amp;</span><span class="number">10</span>).<span class="ident">unwrap</span>())],
);
<span class="kw">let</span> <span class="ident">session</span> <span class="op">=</span> <span class="ident">req</span>.<span class="ident">head_mut</span>().<span class="ident">get_session</span>();
@ -665,6 +812,17 @@
<span class="ident">session</span>.<span class="ident">renew</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">session</span>.<span class="number">0</span>.<span class="ident">borrow</span>().<span class="ident">status</span>, <span class="ident">SessionStatus</span>::<span class="ident">Renewed</span>);
}
<span class="attribute">#[<span class="ident">test</span>]</span>
<span class="kw">fn</span> <span class="ident">session_entries</span>() {
<span class="kw">let</span> <span class="ident">session</span> <span class="op">=</span> <span class="ident">Session</span>(<span class="ident">Rc</span>::<span class="ident">new</span>(<span class="ident">RefCell</span>::<span class="ident">new</span>(<span class="ident">SessionInner</span>::<span class="ident">default</span>())));
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;test_str&quot;</span>, <span class="string">&quot;val&quot;</span>).<span class="ident">unwrap</span>();
<span class="ident">session</span>.<span class="ident">insert</span>(<span class="string">&quot;test_num&quot;</span>, <span class="number">1</span>).<span class="ident">unwrap</span>();
<span class="kw">let</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">session</span>.<span class="ident">entries</span>();
<span class="ident">map</span>.<span class="ident">contains_key</span>(<span class="string">&quot;test_str&quot;</span>);
<span class="ident">map</span>.<span class="ident">contains_key</span>(<span class="string">&quot;test_num&quot;</span>);
}
}
</pre></div>
</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="actix_session" data-search-js="../../search-index.js"></div>