<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="A session lifecycle strategy where the session cookie expires when the browser’s current session ends."><metaname="keywords"content="rust, rustlang, rust-lang, BrowserSession"><title>BrowserSession in actix_session::config - Rust</title><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/SourceSerif4-Regular-1f7d512b176f0f72.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/SourceSerif4-Bold-124a1ca42af929b6.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><linkrel="stylesheet"href="../../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../../static.files/rustdoc-59deea3733ac6c09.css"id="mainThemeStyle"><linkrel="stylesheet"id="themeStyle"href="../../static.files/light-3bcdcab5f4113412.css"><linkrel="stylesheet"disabledhref="../../static.files/dark-091ecdca18d5df85.css"><linkrel="stylesheet"disabledhref="../../static.files/ayu-45445754dcd01ab2.css"><scriptid="default-settings"></script><scriptsrc="../../static.files/storage-d43fa987303ecbbb.js"></script><scriptdefersrc="sidebar-items.js"></script><scriptdefersrc="../../static.files/main-287cecec4dbb45b0.js"></script><noscript><linkrel="stylesheet"href="../../static.files/noscript-13285aec31fa243e.css"></noscript><linkrel="icon"href="https://actix.rs/favicon.ico"></head><bodyclass="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle">☰</button><aclass="sidebar-logo"href="../../actix_session/index.html"><divclass="logo-container"><imgsrc="https://actix.rs/img/logo.png"alt="logo"></div></a><h2></h2></nav><navclass="sidebar"><aclass="sidebar-logo"href="../../actix_session/index.html"><divclass="logo-container">
<imgsrc="https://actix.rs/img/logo.png"alt="logo"></div></a><h2class="location"><ahref="#">BrowserSession</a></h2><divclass="sidebar-elems"><section><h3><ahref="#implementations">Methods</a></h3><ulclass="block"><li><ahref="#method.state_ttl">state_ttl</a></li><li><ahref="#method.state_ttl_extension_policy">state_ttl_extension_policy</a></li></ul><h3><ahref="#trait-implementations">Trait Implementations</a></h3><ulclass="block"><li><ahref="#impl-Clone-for-BrowserSession">Clone</a></li><li><ahref="#impl-Debug-for-BrowserSession">Debug</a></li><li><ahref="#impl-Default-for-BrowserSession">Default</a></li><li><ahref="#impl-From%3CBrowserSession%3E-for-SessionLifecycle">From<BrowserSession></a></li></ul><h3><ahref="#synthetic-implementations">Auto Trait Implementations</a></h3><ulclass="block"><li><ahref="#impl-RefUnwindSafe-for-BrowserSession">RefUnwindSafe</a></li><li><ahref="#impl-Send-for-BrowserSession">Send</a></li><li><ahref="#impl-Sync-for-BrowserSession">Sync</a></li><li><ahref="#impl-Unpin-for-BrowserSession">Unpin</a></li><li><ahref="#impl-UnwindSafe-for-BrowserSession">UnwindSafe</a></li></ul><h3><ahref="#blanket-implementations">Blanket Implementations</a></h3><ulclass="block"><li><ahref="#impl-Any-for-BrowserSession">Any</a></li><li><ahref="#impl-Borrow%3CT%3E-for-BrowserSession">Borrow<T></a></li><li><ahref="#impl-BorrowMut%3CT%3E-for-BrowserSession">BorrowMut<T></a></li><li><ahref="#impl-From%3CT%3E-for-BrowserSession">From<T></a></li><li><ahref="#impl-Instrument-for-BrowserSession">Instrument</a></li><li><ahref="#impl-Into%3CU%3E-for-BrowserSession">Into<U></a></li><li><ahref="#impl-Same%3CT%3E-for-BrowserSession">Same<T></a></li><li><ahref="#impl-ToOwned-for-BrowserSession">ToOwned</a></li><li><ahref="#impl-TryFrom%3CU%3E-for-BrowserSession">TryFrom<U></a></li><li><ahref="#impl-TryInto%3CU%3E-for-BrowserSession">TryInto<U></a></li><li><ahref="#impl-VZip%3CV%3E-for-BrowserSession">VZip<V></a></li><li><ahref="#impl-WithSubscriber-for-BrowserSession">WithSubscriber</a></li></ul></section><h2><ahref="index.html">In actix_session::config</a></h2></div></nav><main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><inputclass="search-input"name="search"aria-label="Run search in the documentation"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><divid="help-button"title="help"tabindex="-1"><ahref="../../help.html">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../../static.files/wheel-5ec35bf9ca753509.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1class="fqn">Struct <ahref="../index.html">actix_session</a>::<wbr><ahref="index.html">config</a>::<wbr><aclass="struct"href="#">BrowserSession</a><buttonid="copy-path"onclick="copy_path(this)"title="Copy item path to clipboard"><imgsrc="../../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="srclink"href="../../src/actix_session/config.rs.html#42-45">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><divclass="item-decl"><preclass="rust struct"><code>pub struct BrowserSession { /* private fields */ }</code></pre></div><detailsclass="rustdoc-toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>A <ahref="enum.SessionLifecycle.html">session lifecycle</a> strategy where the session cookie expires when the
<p>Due to its <code>Into<SessionLifecycle></code> implementation, a <code>BrowserSession</code> can be passed directly
to <ahref="struct.SessionMiddlewareBuilder.html#method.session_lifecycle"title="SessionMiddlewareBuilder::session_lifecycle()"><code>SessionMiddlewareBuilder::session_lifecycle()</code></a>.</p>
</div></details><h2id="implementations"class="small-section-header">Implementations<ahref="#implementations"class="anchor">§</a></h2><divid="implementations-list"><detailsclass="rustdoc-toggle implementors-toggle"open><summary><sectionid="impl-BrowserSession"class="impl has-srclink"><aclass="srclink rightside"href="../../src/actix_session/config.rs.html#47-82">source</a><ahref="#impl-BrowserSession"class="anchor">§</a><h3class="code-header">impl <aclass="struct"href="struct.BrowserSession.html"title="struct actix_session::config::BrowserSession">BrowserSession</a></h3></section></summary><divclass="impl-items"><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.state_ttl"class="method has-srclink"><aclass="srclink rightside"href="../../src/actix_session/config.rs.html#68-71">source</a><h4class="code-header">pub fn <ahref="#method.state_ttl"class="fn">state_ttl</a>(self, ttl: Duration) -> Self</h4></section></summary><divclass="docblock"><p>Sets a time-to-live (TTL) when storing the session state in the storage backend.</p>
<p>We do not want to store session states indefinitely, otherwise we will inevitably run out of
storage by holding on to the state of countless abandoned or expired sessions!</p>
<p>We are dealing with the lifecycle of two uncorrelated object here: the session cookie
and the session state. It is not a big issue if the session state outlives the cookie—
we are wasting some space in the backend storage, but it will be cleaned up eventually.
What happens, instead, if the cookie outlives the session state? A new session starts—
e.g. if sessions are being used for authentication, the user is de-facto logged out.</p>
<p>It is not possible to predict with certainty how long a browser session is going to
last—you need to provide a reasonable upper bound. You do so via <code>state_ttl</code>—it dictates
what TTL should be used for session state when the lifecycle of the session cookie is
tied to the browser session length. <ahref="../struct.SessionMiddleware.html"title="SessionMiddleware"><code>SessionMiddleware</code></a> will default to 1 day if
<code>state_ttl</code> is left unspecified.</p>
<p>You can mitigate the risk of the session cookie outliving the session state by
specifying a more aggressive state TTL extension policy - check out
<ahref="struct.BrowserSession.html#method.state_ttl_extension_policy"title="BrowserSession::state_ttl_extension_policy"><code>BrowserSession::state_ttl_extension_policy</code></a> for more details.</p>
</div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.state_ttl_extension_policy"class="method has-srclink"><aclass="srclink rightside"href="../../src/actix_session/config.rs.html#78-81">source</a><h4class="code-header">pub fn <ahref="#method.state_ttl_extension_policy"class="fn">state_ttl_extension_policy</a>(<br> self,<br> ttl_extension_policy: <aclass="enum"href="enum.TtlExtensionPolicy.html"title="enum actix_session::config::TtlExtensionPolicy">TtlExtensionPolicy</a><br>) -> Self</h4></section></summary><divclass="docblock"><p>Determine under what circumstances the TTL of your session state should be extended.</p>
<p>Defaults to <ahref="enum.TtlExtensionPolicy.html#variant.OnStateChanges"title="TtlExtensionPolicy::OnStateChanges"><code>TtlExtensionPolicy::OnStateChanges</code></a> if left unspecified.</p>
<p>See <ahref="enum.TtlExtensionPolicy.html"title="TtlExtensionPolicy"><code>TtlExtensionPolicy</code></a> for more details.</p>
</div></details></div></details></div><h2id="trait-implementations"class="small-section-header">Trait Implementations<ahref="#trait-implementations"class="anchor">§</a></h2><divid="trait-implementations-list"><detailsclass="rustdoc-toggle implementors-toggle"open><summary><sectionid="impl-Clone-for-BrowserSession"class="impl has-srclink"><aclass="srclink rightside"href="../../src/actix_session/config.rs.html#41">source</a><ahref="#impl-Clone-for-BrowserSession"class="anchor">§</a><h3class="code-header">impl <aclass="trait"href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html"title="trait core::clone::Clone">Clone</a> for <aclass="struct"href="struct.BrowserSession.html"title="struct actix_session::config::BrowserSession">BrowserSession</a></h3></section></summary><divclass="impl-items"><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.clone"class="method trait-impl has-srclink"><aclass="srclink rightside"href="../../src/actix_session/config.rs.html#41">source</a><ahref="#method.clone"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone"class="fn">clone</a>(&self) -><aclass="struct"href="struct.BrowserSession.html"title="struct actix_session::config::BrowserSession">BrowserSession</a></h4></section></summary><divclass='docblock'>Returns a copy of the value. <ahref="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.clone_from"class="method trait-impl has-srclink"><spanclass="rightside"><spanclass="since"title="Stable since Rust version 1.0.0">1.0.0</span> · <aclass="srclink"href="https://doc.rust-lang.org/nightly/src/core/clone.rs.html#132-134">source</a></span><ahref="#method.clone_from"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from"class="fn">clone_from</a>(&mut self, source: <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>Self)</h4></section></summary><divclass='docblock'>Performs copy-assignment from <code>source</code>. <ahref="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></div></details></div></details><detailsclass="rustdoc-toggle implementors-toggle"open><summary><sectionid="impl-Debug-for-BrowserSession"class="impl has-srclink"><aclass="srclink rightside"href="../../src/actix_session/config.rs.html#41">source</a><ahref="#impl-Debug-for-BrowserSession"class="anchor">§</a><h3class="code-header">impl <aclass="trait"href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html"title="trait core::fmt::Debug">Debug</a> for <aclass="struct"href="struct.BrowserSession.html"title="struct actix_session::config::BrowserSession">BrowserSession</a></h3></section></summary><divclass="impl-items"><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.fmt"class="method trait-impl has-srclink"><aclass="srclink rightside"href="../../src/actix_session/config.rs.html#41">source</a><ahref="#method.fmt"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt"class="fn">fmt</a>(&self, f: &mut <aclass="struct"href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html"title="struct core::fmt::Formatter">Formatter</a><'_>) -><aclass="type"href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html"title="type core::fmt::Result">Result</a></h4></section></summary><divclass='docblock'>Formats the value using the given formatter. <ahref="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><detailsclass="rustdoc-toggle implementors-toggle"open><summary><sectionid="impl-Default-for-BrowserSession"class="imp
</div></details></div></details><detailsclass="rustdoc-toggle implementors-toggle"><summary><sectionid="impl-Instrument-for-BrowserSession"class="impl has-srclink"><aclass="srclink rightside"href="https://docs.rs/tracing/0.1.37/src/tracing/instrument.rs.html#276">source</a><ahref="#impl-Instrument-for-BrowserSession"class="anchor">§</a><h3class="code-header">impl<T><aclass="trait"href="https://docs.rs/tracing/0.1.37/tracing/instrument/trait.Instrument.html"title="trait tracing::instrument::Instrument">Instrument</a> for T</h3></section></summary><divclass="impl-items"><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.instrument"class="method trait-impl has-srclink"><aclass="srclink rightside"href="https://docs.rs/tracing/0.1.37/src/tracing/instrument.rs.html#82">source</a><ahref="#method.instrument"class="anchor">§</a><h4class="code-header">fn <ahref="https://docs.rs/tracing/0.1.37/tracing/instrument/trait.Instrument.html#method.instrument"class="fn">instrument</a>(self, span: <aclass="struct"href="https://docs.rs/tracing/0.1.37/tracing/span/struct.Span.html"title="struct tracing::span::Span">Span</a>) -><aclass="struct"href="https://docs.rs/tracing/0.1.37/tracing/instrument/struct.Instrumented.html"title="struct tracing::instrument::Instrumented">Instrumented</a><Self></h4></section></summary><divclass='docblock'>Instruments this type with the provided <ahref="https://docs.rs/tracing/0.1.37/tracing/span/struct.Span.html"title="Span"><code>Span</code></a>, returning an
<code>Instrumented</code> wrapper. <ahref="https://docs.rs/tracing/0.1.37/tracing/instrument/trait.Instrument.html#method.instrument">Read more</a></div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.in_current_span"class="method trait-impl has-srclink"><aclass="srclink rightside"href="https://docs.rs/tracing/0.1.37/src/tracing/instrument.rs.html#121">source</a><ahref="#method.in_current_span"class="anchor">§</a><h4class="code-header">fn <ahref="https://docs.rs/tracing/0.1.37/tracing/instrument/trait.Instrument.html#method.in_current_span"class="fn">in_current_span</a>(self) -><aclass="struct"href="https://docs.rs/tracing/0.1.37/tracing/instrument/struct.Instrumented.html"title="struct tracing::instrument::Instrumented">Instrumented</a><Self></h4></section></summary><divclass='docblock'>Instruments this type with the <ahref="https://docs.rs/tracing/0.1.37/tracing/span/struct.Span.html#method.current">current</a><ahref="https://docs.rs/tracing/0.1.37/tracing/span/struct.Span.html"><code>Span</code></a>, returning an
</div></details></div></details><detailsclass="rustdoc-toggle implementors-toggle"><summary><sectionid="impl-Same%3CT%3E-for-BrowserSession"class="impl has-srclink"><aclass="srclink rightside"href="https://docs.rs/typenum/1.15.0/src/typenum/type_operators.rs.html#34">source</a><ahref="#impl-Same%3CT%3E-for-BrowserSession"class="anchor">§</a><h3class="code-header">impl<T><aclass="trait"href="https://docs.rs/typenum/1.15.0/typenum/type_operators/trait.Same.html"title="trait typenum::type_operators::Same">Same</a><T> for T</h3></section></summary><divclass="impl-items"><detailsclass="rustdoc-toggle"open><summary><sectionid="associatedtype.Output"class="associatedtype trait-impl has-srclink"><ahref="#associatedtype.Output"class="anchor">§</a><h4class="code-header">type <ahref="https://docs.rs/typenum/1.15.0/typenum/type_operators/trait.Same.html#associatedtype.Output"class="associatedtype">Output</a> = T</h4></section></summary><divclass='docblock'>Should always be <code>Self</code></div></details></div></details><detailsclass="rustdoc-toggle implementors-toggle"><summary><sectionid="impl-ToOwned-for-BrowserSession"class="impl has-srclink"><aclass="srclink rightside"href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#82">source</a><ahref="#impl-ToOwned-for-BrowserSession"class="anchor">§</a><h3class="code-header">impl<T><aclass="trait"href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html"title="trait alloc::borrow::ToOwned">ToOwned</a> for T<spanclass="where fmt-newline">where<br> T: <aclass="trait"href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html"title="trait core::clone::Clone">Clone</a>,</span></h3></section></summary><divclass="impl-items"><detailsclass="rustdoc-toggle"open><summary><sectionid="associatedtype.Owned"class="associatedtype trait-impl has-srclink"><ahref="#associatedtype.Owned"class="anchor">§</a><h4class="code-header">type <ahref="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#associatedtype.Owned"class="associatedtype">Owned</a> = T</h4></section></summary><divclass='docblock'>The resulting type after obtaining ownership.</div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.to_owned"class="method trait-impl has-srclink"><aclass="srclink rightside"href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#87">source</a><ahref="#method.to_owned"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#tymethod.to_owned"class="fn">to_owned</a>(&self) -> T</h4></section></summary><divclass='docblock'>Creates owned data from borrowed data, usually by cloning. <ahref="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.clone_into"class="method trait-impl has-srclink"><aclass="srclink rightside"href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#91">source</a><ahref="#method.clone_into"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into"class="fn">clone_into</a>(&self, target: <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T)</h4></section></summary><divclass='docblock'>Uses borrowed data to replace owned data, usually by cloning. <ahref="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><detailsclass="rustdoc-toggle implementors-toggle"><summary><sectionid="impl-TryFrom%3CU%3E-for-BrowserSession"class="impl has-srclink"><aclass="srclink rightside"href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#775">source</a><ahref="#impl-TryFrom%3CU%3E-for-BrowserSession"class="anchor">§</a><h3class="code-header">impl<T, U&
<ahref="https://docs.rs/tracing/0.1.37/tracing/instrument/struct.WithDispatch.html"title="WithDispatch"><code>WithDispatch</code></a> wrapper. <ahref="https://docs.rs/tracing/0.1.37/tracing/instrument/trait.WithSubscriber.html#method.with_subscriber">Read more</a></div></details><detailsclass="rustdoc-toggle method-toggle"open><summary><sectionid="method.with_current_subscriber"class="method trait-impl has-srclink"><aclass="srclink rightside"href="https://docs.rs/tracing/0.1.37/src/tracing/instrument.rs.html#221">source</a><ahref="#method.with_current_subscriber"class="anchor">§</a><h4class="code-header">fn <ahref="https://docs.rs/tracing/0.1.37/tracing/instrument/trait.WithSubscriber.html#method.with_current_subscriber"class="fn">with_current_subscriber</a>(self) -><aclass="struct"href="https://docs.rs/tracing/0.1.37/tracing/instrument/struct.WithDispatch.html"title="struct tracing::instrument::WithDispatch">WithDispatch</a><Self></h4></section></summary><divclass='docblock'>Attaches the current <ahref="https://docs.rs/tracing/0.1.37/tracing/dispatcher/index.html#setting-the-default-subscriber">default</a><ahref="https://docs.rs/tracing-core/0.1.22/tracing_core/subscriber/trait.Subscriber.html"><code>Subscriber</code></a> to this type, returning a