Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server::send_text_owned #36

Merged
merged 4 commits into from
Jun 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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