<!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="API documentation for the Rust `WebsocketContext` struct in crate `actix_web`."><metaname="keywords"content="rust, rustlang, rust-lang, WebsocketContext"><title>actix_web::ws::WebsocketContext - Rust</title><linkrel="stylesheet"type="text/css"href="../../normalize.css"><linkrel="stylesheet"type="text/css"href="../../rustdoc.css"id="mainThemeStyle"><linkrel="stylesheet"type="text/css"href="../../dark.css"><linkrel="stylesheet"type="text/css"href="../../light.css"id="themeStyle"><scriptsrc="../../storage.js"></script></head><bodyclass="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="sidebar"><divclass="sidebar-menu">☰</div><pclass='location'>Struct WebsocketContext</p><divclass="sidebar-elems"><divclass="block items"><aclass="sidebar-title"href="#methods">Methods</a><divclass="sidebar-links"><ahref="#method.create">create</a><ahref="#method.with_factory">with_factory</a><ahref="#method.write_raw">write_raw</a><ahref="#method.state">state</a><ahref="#method.request">request</a><ahref="#method.drain">drain</a><ahref="#method.text">text</a><ahref="#method.binary">binary</a><ahref="#method.ping">ping</a><ahref="#method.pong">pong</a><ahref="#method.close">close</a><ahref="#method.connected">connected</a><ahref="#method.handle">handle</a></div><aclass="sidebar-title"href="#implementations">Trait Implementations</a><divclass="sidebar-links"><ahref="#impl-ActorContext">ActorContext</a><ahref="#impl-AsyncContext%3CA%3E">AsyncContext<A></a><ahref="#impl-WsWriter">WsWriter</a><ahref="#impl-AsyncContextParts%3CA%3E">AsyncContextParts<A></a><ahref="#impl-ToEnvelope%3CA%2C%20M%3E">ToEnvelope<A, M></a></div><aclass="sidebar-title"href="#synthetic-implementations">Auto Trait Implementations</a><divclass="sidebar-links"><ahref="#impl-Send">!Send</a><ahref="#impl-Sync">!Sync</a></div></div><pclass='location'><ahref='../index.html'>actix_web</a>::<wbr><ahref='index.html'>ws</a></p><script>window.sidebarCurrent={name:'WebsocketContext',ty:'struct',relpath:''};</script><scriptdefersrc="sidebar-items.js"></script></div></nav><divclass="theme-picker"><buttonid="theme-picker"aria-label="Pick another theme!"><imgsrc="../../brush.svg"width="18"alt="Pick another theme!"></button><divid="theme-choices"></div></div><scriptsrc="../../theme.js"></script><navclass="sub"><formclass="search-form js-only"><divclass="search-container"><inputclass="search-input"name="search"autocomplete="off"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><aid="settings-menu"href="../../settings.html"><imgsrc="../../wheel.svg"width="18"alt="Change settings"></a></div></form></nav><sectionid="main"class="content"><h1class='fqn'><spanclass='in-band'>Struct <ahref='../index.html'>actix_web</a>::<wbr><ahref='index.html'>ws</a>::<wbr><aclass="struct"href=''>WebsocketContext</a></span><spanclass='out-of-band'><spanid='render-detail'><aid="toggle-all-docs"href="javascript:void(0)"title="collapse all docs">[<spanclass='inner'>−</span>]</a></span><aclass='srclink'href='../../src/actix_web/ws/context.rs.html#28-36'title='goto source code'>[src]</a></span></h1><divclass="docblock type-decl"><preclass='rust struct'>pub struct WebsocketContext<A, S = <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>><spanclass="where fmt-newline">where<br> A: <aclass="trait"href="../../actix_web/actix/actix/trait.Actor.html"title="trait actix_web::actix::actix::Actor">Actor</a><Context = <aclass="struct"href="../../actix_web/ws/struct.WebsocketContext.html"title="struct actix_web::ws::WebsocketContext">WebsocketContext</a><A, S&
</div><h4id='method.connected'class="method"><spanid='connected.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>pub fn <ahref='#method.connected'class='fnname'>connected</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span></td><td><spanclass='out-of-band'><divclass='ghost'></div><aclass='srclink'href='../../src/actix_web/ws/context.rs.html#214-216'title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><divclass='docblock'><p>Check if connection still open</p>
</div></div><h3id='impl-AsyncContext%3CA%3E'class='impl'><spanclass='in-band'><tableclass='table-display'><tbody><tr><td><code>impl<A, S><aclass="trait"href="../../actix_web/actix/actix/trait.AsyncContext.html"title="trait actix_web::actix::actix::AsyncContext">AsyncContext</a><A> for <aclass="struct"href="../../actix_web/ws/struct.WebsocketContext.html"title="struct actix_web::ws::WebsocketContext">WebsocketContext</a><A, S><spanclass="where fmt-newline">where<br> A: <aclass="trait"href="../../actix_web/actix/actix/trait.Actor.html"title="trait actix_web::actix::actix::Actor">Actor</a><Context = Self>, </span></code><ahref='#impl-AsyncContext%3CA%3E'class='anchor'></a></span></td><td><spanclass='out-of-band'><divclass='ghost'></div><aclass='srclink'href='../../src/actix_web/ws/context.rs.html#53-87'title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><divclass='impl-items'><h4id='method.spawn'class="method"><spanid='spawn.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#tymethod.spawn'class='fnname'>spawn</a><F>(&mut self, fut: F) -><aclass="struct"href="../../actix_web/actix/actix/struct.SpawnHandle.html"title="struct actix_web::actix::actix::SpawnHandle">SpawnHandle</a><spanclass="where fmt-newline">where<br> F: <aclass="trait"href="../../actix_web/actix/actix/trait.ActorFuture.html"title="trait actix_web::actix::actix::ActorFuture">ActorFuture</a><Item = <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error = <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Actor = A> + 'static, </span></code></span></td><td><spanclass='out-of-band'><divclass='ghost'></div><aclass='srclink'href='../../src/actix_web/ws/context.rs.html#57-62'title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><divclass='docblock'><p>Spawn async future into context. Returns handle of the item, could be used for cancelling execution. <ahref="../../actix_web/actix/actix/trait.AsyncContext.html#tymethod.spawn">Read more</a></p>
</div><h4id='method.wait'class="method"><spanid='wait.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#tymethod.wait'class='fnname'>wait</a><F>(&mut self, fut: F) <spanclass="where fmt-newline">where<br> F: <aclass="trait"href="../../actix_web/actix/actix/trait.ActorFuture.html"title="trait actix_web::actix::actix::ActorFuture">ActorFuture</a><Item = <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error = <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Actor = A> + 'static, </span></code></span></td><td><spanclass='out-of-band'><divclass='ghost'></div><aclass='srclink'href='../../src/actix_web/ws/context.rs.html#64-69'title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><divclass='docblock'><p>Spawn future into the context. Stop processing any of incoming events until this future resolves. <ahref="../../actix_web/actix/actix/trait.AsyncContext.html#tymethod.wait">Read more</a></p>
</div><h4id='method.cancel_future'class="method"><spanid='cancel_future.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#tymethod.cancel_future'class='fnname'>cancel_future</a>(&mut self, handle: <aclass="struct"href="../../actix_web/actix/actix/struct.SpawnHandle.html"title="struct actix_web::actix::actix::SpawnHandle">SpawnHandle</a>) -><aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span></td><td><spanclass='out-of-band'><divclass='ghost'></div><aclass='srclink'href='../../src/actix_web/ws/context.rs.html#79-81'title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><divclass='docblock'><p>Cancel future. handle is a value returned by <code>spawn</code> method.</p>
</div><h4id='method.address'class="method"><spanid='address.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#tymethod.address'class='fnname'>address</a>(&self) -><aclass="struct"href="../../actix_web/actix/actix/struct.Addr.html"title="struct actix_web::actix::actix::Addr">Addr</a><A></code></span></td><td><spanclass='out-of-band'><divclass='ghost'></div><aclass='srclink'href='../../src/actix_web/ws/context.rs.html#84-86'title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><divclass='docblock'><p>Return <code>Address</code> of the context</p>
</div><h4id='tymethod.waiting'class="tymethod"><spanid='waiting.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#tymethod.waiting'class='fnname'>waiting</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></td><td></td></tr></tbody></table></span></h4><divclass='docblock'><p>Check if context is paused (waiting for future completion or stopping)</p>
</div><h4id='method.add_stream'class="method"><spanid='add_stream.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#method.add_stream'class='fnname'>add_stream</a><S>(&mut self, fut: S) -><aclass="struct"href="../../actix_web/actix/actix/struct.SpawnHandle.html"title="struct actix_web::actix::actix::SpawnHandle">SpawnHandle</a><spanclass="where fmt-newline">where<br> A: <aclass="trait"href="../../actix_web/actix/actix/trait.StreamHandler.html"title="trait actix_web::actix::actix::StreamHandler">StreamHandler</a><<S as <aclass="trait"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html"title="trait futures::stream::Stream">Stream</a>>::<aclass="type"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html#associatedtype.Item"title="type futures::stream::Stream::Item">Item</a>, <S as <aclass="trait"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html"title="trait futures::stream::Stream">Stream</a>>::<aclass="type"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html#associatedtype.Error"title="type futures::stream::Stream::Error">Error</a>>,<br> S: <aclass="trait"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html"title="trait futures::stream::Stream">Stream</a> + 'static, </span></code></td><td></td></tr></tbody></table></span></h4><divclass='docblock'><p>This method register stream to an actor context and allows to handle <code>Stream</code> in similar way as normal actor messages. <ahref="../../actix_web/actix/actix/trait.AsyncContext.html#method.add_stream">Read more</a></p>
</div><h4id='method.add_message_stream'class="method"><spanid='add_message_stream.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#method.add_message_stream'class='fnname'>add_message_stream</a><S>(&mut self, fut: S) <spanclass="where fmt-newline">where<br> A: <aclass="trait"href="../../actix_web/actix/actix/trait.Handler.html"title="trait actix_web::actix::actix::Handler">Handler</a><<S as <aclass="trait"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html"title="trait futures::stream::Stream">Stream</a>>::<aclass="type"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html#associatedtype.Item"title="type futures::stream::Stream::Item">Item</a>>,<br> S: <aclass="trait"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html"title="trait futures::stream::Stream">Stream</a><Error = <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + 'static,<br> <S as <aclass="trait"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html"title="trait futures::stream::Stream">Stream</a>>::<aclass="type"href="https://docs.rs/futures/0.1/futures/stream/trait.Stream.html#associatedtype.Item"title="type futures::stream::Stream::Item">Item</a>: <aclass="trait"href="../../actix_web/actix/actix/trait.Message.html"title="trait actix_web::actix::actix::Message">Message</a>, </span></code></td><td></td></tr></tbody></table></span></h4><divclass='docblock'><p>This method is similar to <code>add_stream</code> but it skips stream errors. <ahref="../../actix_web/actix/actix/trait.AsyncContext.html#method.add_message_stream">Read more</a></p>
</div><h4id='method.notify'class="method"><spanid='notify.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#method.notify'class='fnname'>notify</a><M>(&mut self, msg: M) <spanclass="where fmt-newline">where<br> A: <aclass="trait"href="../../actix_web/actix/actix/trait.Handler.html"title="trait actix_web::actix::actix::Handler">Handler</a><M>,<br> M: <aclass="trait"href="../../actix_web/actix/actix/trait.Message.html"title="trait actix_web::actix::actix::Message">Message</a> + 'static, </span></code></td><td></td></tr></tbody></table></span></h4><divclass='docblock'><p>Send message <code>msg</code> to self.</p>
</div><h4id='method.notify_later'class="method"><spanid='notify_later.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#method.notify_later'class='fnname'>notify_later</a><M>(&mut self, msg: M, after: <aclass="struct"href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html"title="struct core::time::Duration">Duration</a>) -><aclass="struct"href="../../actix_web/actix/actix/struct.SpawnHandle.html"title="struct actix_web::actix::actix::SpawnHandle">SpawnHandle</a><spanclass="where fmt-newline">where<br> A: <aclass="trait"href="../../actix_web/actix/actix/trait.Handler.html"title="trait actix_web::actix::actix::Handler">Handler</a><M>,<br> M: <aclass="trait"href="../../actix_web/actix/actix/trait.Message.html"title="trait actix_web::actix::actix::Message">Message</a> + 'static, </span></code></td><td></td></tr></tbody></table></span></h4><divclass='docblock'><p>Send message <code>msg</code> to self after specified period of time. Returns spawn handle which could be used for cancellation. Notification get cancelled if context's stop method get called. <ahref="../../actix_web/actix/actix/trait.AsyncContext.html#method.notify_later">Read more</a></p>
</div><h4id='method.run_later'class="method"><spanid='run_later.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#method.run_later'class='fnname'>run_later</a><F>(&mut self, dur: <aclass="struct"href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html"title="struct core::time::Duration">Duration</a>, f: F) -><aclass="struct"href="../../actix_web/actix/actix/struct.SpawnHandle.html"title="struct actix_web::actix::actix::SpawnHandle">SpawnHandle</a><spanclass="where fmt-newline">where<br> F: <aclass="trait"href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html"title="trait core::ops::function::FnOnce">FnOnce</a>(<aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>A, &mut <A as <aclass="trait"href="../../actix_web/actix/actix/trait.Actor.html"title="trait actix_web::actix::actix::Actor">Actor</a>>::<aclass="type"href="../../actix_web/actix/actix/trait.Actor.html#associatedtype.Context"title="type actix_web::actix::actix::Actor::Context">Context</a>) + 'static, </span></code></td><td></td></tr></tbody></table></span></h4><divclass='docblock'><p>Execute closure after specified period of time within same Actor and Context. Execution get cancelled if context's stop method get called. <ahref="../../actix_web/actix/actix/trait.AsyncContext.html#method.run_later">Read more</a></p>
</div><h4id='method.run_interval'class="method"><spanid='run_interval.v'class='invisible'><tableclass='table-display'><tbody><tr><td><code>fn <ahref='../../actix_web/actix/actix/trait.AsyncContext.html#method.run_interval'class='fnname'>run_interval</a><F>(&mut self, dur: <aclass="struct"href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html"title="struct core::time::Duration">Duration</a>, f: F) -><aclass="struct"href="../../actix_web/actix/actix/struct.SpawnHandle.html"title="struct actix_web::actix::actix::SpawnHandle">SpawnHandle</a><spanclass="where fmt-newline">where<br> F: <aclass="trait"href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html"title="trait core::ops::function::FnMut">FnMut</a>(<aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>A, &mut <A as <aclass="trait"href="../../actix_web/actix/actix/trait.Actor.html"title="trait actix_web::actix::actix::Actor">Actor</a>>::<aclass="type"href="../../actix_web/actix/actix/trait.Actor.html#associatedtype.Context"title="type actix_web::actix::actix::Actor::Context">Context</a>) + 'static, </span></code></td><td></td></tr></tbody></table></span></h4><divclass='docblock'><p>Spawns job to execute closure with specified interval</p>
Auto Trait Implementations<ahref='#synthetic-implementations'class='anchor'></a>
</h2>
<divid='synthetic-implementations-list'>
<h3id='impl-Send'class='impl'><spanclass='in-band'><tableclass='table-display'><tbody><tr><td><code>impl<A, S = <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> !<aclass="trait"href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html"title="trait core::marker::Send">Send</a> for <aclass="struct"href="../../actix_web/ws/struct.WebsocketContext.html"title="struct actix_web::ws::WebsocketContext">WebsocketContext</a><A, S></code><ahref='#impl-Send'class='anchor'></a></span></td><td><spanclass='out-of-band'></span></td></tr></tbody></table></h3><divclass='impl-items'></div><h3id='impl-Sync'class='impl'><spanclass='in-band'><tableclass='table-display'><tbody><tr><td><code>impl<A, S = <aclass="primitive"href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> !<aclass="trait"href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html"title="trait core::marker::Sync">Sync</a> for <aclass="struct"href="../../actix_web/ws/struct.WebsocketContext.html"title="struct actix_web::ws::WebsocketContext">WebsocketContext</a><A, S></code><ahref='#impl-Sync'class='anchor'></a></span></td><td><spanclass='out-of-band'></span></td></tr></tbody></table></h3><divclass='impl-items'></div></div></section><sectionid="search"class="content hidden"></section><sectionclass="footer"></section><asideid="help"class="hidden"><div><h1class="hidden">Help</h1><divclass="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>⏎</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><divclass="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g. <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g. <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath="../../";window.currentCrate="actix_web";</script><scriptsrc="../../aliases.js"></script><scriptsrc="../../main.js"></script><scriptdefersrc="../../search-index.js"></script></body></html>