Skip to content

Commit

Permalink
Server::send_text_owned (#36)
Browse files Browse the repository at this point in the history
* Server::send_text_owned

* Tune rustdoc comments

* Grammar

Co-authored-by: Niklas Adolfsson <[email protected]>
  • Loading branch information
maciejhirsz and niklasad1 authored Jun 11, 2021
1 parent 685fd44 commit 88007ee
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Sender<T> {
self.send_frame(&mut header, &mut Storage::Shared(data.as_ref().as_bytes())).await
}

/// Send a text value over the websocket connection.
///
/// This method performs one copy fewer than [`Sender::send_text`].
pub async fn send_text_owned(&mut self, data: String) -> Result<(), Error> {
let mut header = Header::new(OpCode::Text);
self.send_frame(&mut header, &mut Storage::Owned(data.into_bytes())).await
}

/// Send some binary data over the websocket connection.
pub async fn send_binary(&mut self, data: impl AsRef<[u8]>) -> Result<(), Error> {
let mut header = Header::new(OpCode::Binary);
Expand All @@ -440,8 +448,8 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Sender<T> {

/// Send some binary data over the websocket connection.
///
/// In contrast to [`Sender::send_binary`] the provided data is modified
/// in-place, e.g. if masking is necessary.
/// This method performs one copy fewer than [`Sender::send_binary`].
/// The `data` buffer may be modified by this method, e.g. if masking is necessary.
pub async fn send_binary_mut(&mut self, mut data: impl AsMut<[u8]>) -> Result<(), Error> {
let mut header = Header::new(OpCode::Binary);
self.send_frame(&mut header, &mut Storage::Unique(data.as_mut())).await
Expand Down

0 comments on commit 88007ee

Please sign in to comment.