@@ -229,7 +229,14 @@ impl<'a> ws::Message for Message<'a> {
229229 }
230230}
231231
232- /// Represents a WebSocket message.
232+ /// Represents an owned WebSocket message.
233+ ///
234+ /// `OwnedMessage`s are generated when the user receives a message (since the data
235+ /// has to be copied out of the network buffer anyway).
236+ /// If you would like to create a message out of borrowed data to use for sending
237+ /// please use the `Message` struct (which contains a `Cow`).
238+ ///
239+ /// Note that `OwnedMessage` can `Message` can be converted into each other.
233240#[ derive( Eq , PartialEq , Clone , Debug ) ]
234241pub enum OwnedMessage {
235242 /// A message containing UTF-8 text data
@@ -249,13 +256,28 @@ pub enum OwnedMessage {
249256}
250257
251258impl OwnedMessage {
259+ /// Checks if this message is a close message.
260+ ///
261+ ///```rust
262+ ///# use websocket::OwnedMessage;
263+ ///assert!(OwnedMessage::Close(None).is_close());
264+ ///```
252265 pub fn is_close ( & self ) -> bool {
253266 match * self {
254267 OwnedMessage :: Close ( _) => true ,
255268 _ => false ,
256269 }
257270 }
258271
272+ /// Checks if this message is a control message.
273+ /// Control messages are either `Close`, `Ping`, or `Pong`.
274+ ///
275+ ///```rust
276+ ///# use websocket::OwnedMessage;
277+ ///assert!(OwnedMessage::Ping(vec![]).is_control());
278+ ///assert!(OwnedMessage::Pong(vec![]).is_control());
279+ ///assert!(OwnedMessage::Close(None).is_control());
280+ ///```
259281 pub fn is_control ( & self ) -> bool {
260282 match * self {
261283 OwnedMessage :: Close ( _) => true ,
@@ -265,17 +287,40 @@ impl OwnedMessage {
265287 }
266288 }
267289
290+ /// Checks if this message is a data message.
291+ /// Data messages are either `Text` or `Binary`.
292+ ///
293+ ///```rust
294+ ///# use websocket::OwnedMessage;
295+ ///assert!(OwnedMessage::Text("1337".to_string()).is_data());
296+ ///assert!(OwnedMessage::Binary(vec![]).is_data());
297+ ///```
268298 pub fn is_data ( & self ) -> bool {
269299 !self . is_control ( )
270300 }
271301
302+ /// Checks if this message is a ping message.
303+ /// `Ping` messages can come at any time and usually generate a `Pong` message
304+ /// response.
305+ ///
306+ ///```rust
307+ ///# use websocket::OwnedMessage;
308+ ///assert!(OwnedMessage::Ping("ping".to_string().into_bytes()).is_ping());
309+ ///```
272310 pub fn is_ping ( & self ) -> bool {
273311 match * self {
274312 OwnedMessage :: Ping ( _) => true ,
275313 _ => false ,
276314 }
277315 }
278316
317+ /// Checks if this message is a pong message.
318+ /// `Pong` messages are usually sent only in response to `Ping` messages.
319+ ///
320+ ///```rust
321+ ///# use websocket::OwnedMessage;
322+ ///assert!(OwnedMessage::Pong("pong".to_string().into_bytes()).is_pong());
323+ ///```
279324 pub fn is_pong ( & self ) -> bool {
280325 match * self {
281326 OwnedMessage :: Pong ( _) => true ,
0 commit comments