Skip to content

Commit

Permalink
Return any impl of Message in recv_message, fixes #112
Browse files Browse the repository at this point in the history
  • Loading branch information
illegalprime authored and Michael Eden committed Apr 10, 2017
1 parent bf05966 commit 0dc2417
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,22 @@ impl<S> Client<S>
}

/// Reads a single message from this receiver.
pub fn recv_message<'m, M, I>(&mut self) -> WebSocketResult<M>
where M: ws::Message<'m, DataFrame, DataFrameIterator = I>,
I: Iterator<Item = DataFrame>
///
/// ```rust,no_run
/// use websocket::{ClientBuilder, Message};
/// let mut client = ClientBuilder::new("ws://localhost:3000")
/// .unwrap()
/// .connect_insecure()
/// .unwrap();
///
/// client.send_message(&Message::text("Hello world!")).unwrap();
///
/// let message: Message = client.recv_message().unwrap();
/// ```
pub fn recv_message<'m, M, I, D>(&mut self) -> WebSocketResult<M>
where M: ws::Message<'m, D, DataFrameIterator = I>,
I: Iterator<Item = D>,
D: DataFrameable
{
self.receiver.recv_message(&mut self.stream)
}
Expand Down
7 changes: 4 additions & 3 deletions src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ impl<R> Reader<R>
}

/// Reads a single message from this receiver.
pub fn recv_message<'m, M, I>(&mut self) -> WebSocketResult<M>
where M: ws::Message<'m, DataFrame, DataFrameIterator = I>,
I: Iterator<Item = DataFrame>
pub fn recv_message<'m, M, D, I>(&mut self) -> WebSocketResult<M>
where M: ws::Message<'m, D, DataFrameIterator = I>,
I: Iterator<Item = D>,
D: DataFrameable
{
self.receiver.recv_message(&mut self.stream)
}
Expand Down

0 comments on commit 0dc2417

Please sign in to comment.