pub struct WebSocketConn { /* private fields */ }Expand description
A struct that represents an specific websocket connection.
This can be thought of as a combination of a async_tungstenite::WebSocketStream and a
trillium::Conn, as it contains a combination of their fields and
associated functions.
The WebSocketConn implements Stream<Item=Result<Message, Error>>,
and can be polled with StreamExt::next
Implementations§
Source§impl WebSocketConn
impl WebSocketConn
Sourcepub async fn send_string(&mut self, string: String) -> Result<()>
pub async fn send_string(&mut self, string: String) -> Result<()>
send a Message::Text variant
Sourcepub async fn send_bytes(&mut self, bin: Vec<u8>) -> Result<()>
pub async fn send_bytes(&mut self, bin: Vec<u8>) -> Result<()>
send a Message::Binary variant
Sourcepub async fn send_json(&mut self, json: &impl Serialize) -> Result<()>
pub async fn send_json(&mut self, json: &impl Serialize) -> Result<()>
send a Message::Text that contains json
note that json messages are not actually part of the websocket specification
Sourcepub fn set_peer_ip(&mut self, peer_ip: Option<IpAddr>) -> &mut Self
pub fn set_peer_ip(&mut self, peer_ip: Option<IpAddr>) -> &mut Self
Sets the peer ip for this conn
Sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
retrieves the path part of the request url, up to and excluding any query component
Sourcepub fn querystring(&self) -> &str
pub fn querystring(&self) -> &str
Retrieves the query component of the path, excluding ?. Returns
an empty string if there is no query component.
Sourcepub fn state<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn state<T: Send + Sync + 'static>(&self) -> Option<&T>
retrieve state from the state set that has been accumulated by
trillium handlers run on the trillium::Conn before it
became a websocket. see trillium::Conn::state for more
information
Sourcepub fn state_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T>
pub fn state_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T>
retrieve a mutable borrow of the state from the state set
Sourcepub fn insert_state<T: Send + Sync + 'static>(&mut self, state: T) -> Option<T>
pub fn insert_state<T: Send + Sync + 'static>(&mut self, state: T) -> Option<T>
inserts new state
returns the previously set state of the same type, if any existed
Sourcepub fn state_entry<T: Send + Sync + 'static>(&mut self) -> Entry<'_, T>
pub fn state_entry<T: Send + Sync + 'static>(&mut self) -> Entry<'_, T>
Returns an Entry for the state typeset that can be used with functions like
Entry::or_insert, Entry::or_insert_with, Entry::and_modify, and others.
Sourcepub fn take_state<T: Send + Sync + 'static>(&mut self) -> Option<T>
pub fn take_state<T: Send + Sync + 'static>(&mut self) -> Option<T>
take some type T out of the state set that has been
accumulated by trillium handlers run on the trillium::Conn
before it became a websocket. see trillium::Conn::take_state
for more information
Trait Implementations§
Source§impl AsMut<TypeSet> for WebSocketConn
impl AsMut<TypeSet> for WebSocketConn
Source§impl AsRef<TypeSet> for WebSocketConn
impl AsRef<TypeSet> for WebSocketConn
Source§impl Debug for WebSocketConn
impl Debug for WebSocketConn
Source§impl Stream for WebSocketConn
impl Stream for WebSocketConn
Auto Trait Implementations§
impl Freeze for WebSocketConn
impl !RefUnwindSafe for WebSocketConn
impl Send for WebSocketConn
impl Sync for WebSocketConn
impl Unpin for WebSocketConn
impl UnsafeUnpin for WebSocketConn
impl !UnwindSafe for WebSocketConn
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S> StreamExt for S
impl<S> StreamExt for S
Source§fn next(&mut self) -> NextFuture<'_, Self>where
Self: Unpin,
fn next(&mut self) -> NextFuture<'_, Self>where
Self: Unpin,
Source§fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>
Source§fn count(self) -> CountFuture<Self>where
Self: Sized,
fn count(self) -> CountFuture<Self>where
Self: Sized,
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Source§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
Source§fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
Source§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
Source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n items of the stream. Read moreSource§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Source§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n items of the stream. Read moreSource§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
Source§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
stepth item. Read moreSource§fn chain<U>(self, other: U) -> Chain<Self, U>
fn chain<U>(self, other: U) -> Chain<Self, U>
Source§fn collect<C>(self) -> CollectFuture<Self, C>
fn collect<C>(self) -> CollectFuture<Self, C>
Source§fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>
Source§fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>
fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>
predicate is true and those for which it is
false, and then collects them into two collections. Read moreSource§fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>
Source§fn try_fold<T, E, F, B>(
&mut self,
init: B,
f: F,
) -> TryFoldFuture<'_, Self, F, B>
fn try_fold<T, E, F, B>( &mut self, init: B, f: F, ) -> TryFoldFuture<'_, Self, F, B>
Source§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
Source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
(index, item). Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn nth(&mut self, n: usize) -> NthFuture<'_, Self>where
Self: Unpin,
fn nth(&mut self, n: usize) -> NthFuture<'_, Self>where
Self: Unpin,
nth item of the stream. Read moreSource§fn last(self) -> LastFuture<Self>where
Self: Sized,
fn last(self) -> LastFuture<Self>where
Self: Sized,
Source§fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>
fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>
Source§fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>
fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>
Source§fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>
fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>
Source§fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>
fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>
Source§fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>
Source§fn zip<U>(self, other: U) -> Zip<Self, U>
fn zip<U>(self, other: U) -> Zip<Self, U>
Source§fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>
fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>
Source§fn race<S>(self, other: S) -> Race<Self, S>
fn race<S>(self, other: S) -> Race<Self, S>
other stream, with no preference for either stream when both are ready. Read more