Skip to content

Commit

Permalink
Make close non-fallible
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 18, 2024
1 parent 4c170c3 commit ac57008
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
11 changes: 2 additions & 9 deletions ewebsock/src/native_tungstenite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ pub struct WsSender {

impl Drop for WsSender {
fn drop(&mut self) {
if let Err(err) = self.close() {
log::warn!("Failed to close web-socket: {err:?}");
}
self.close();
}
}

Expand All @@ -35,16 +33,11 @@ impl WsSender {
/// Close the connection.
///
/// This is called automatically when the sender is dropped.
///
/// # Errors
/// This should never fail, except _maybe_ on Web.
#[allow(clippy::unnecessary_wraps)] // To keep the same signature as the Web version
pub fn close(&mut self) -> Result<()> {
pub fn close(&mut self) {
if self.tx.is_some() {
log::debug!("Closing WebSocket");
}
self.tx = None;
Ok(())
}

/// Forget about this sender without closing the connection.
Expand Down
11 changes: 2 additions & 9 deletions ewebsock/src/native_tungstenite_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ pub struct WsSender {

impl Drop for WsSender {
fn drop(&mut self) {
if let Err(err) = self.close() {
log::warn!("Failed to close web-socket: {err:?}");
}
self.close();
}
}

Expand All @@ -30,16 +28,11 @@ impl WsSender {
/// Close the connection.
///
/// This is called automatically when the sender is dropped.
///
/// # Errors
/// This should never fail, except _maybe_ on Web.
#[allow(clippy::unnecessary_wraps)] // To keep the same signature as the Web version
pub fn close(&mut self) -> Result<()> {
pub fn close(&mut self) {
if self.tx.is_some() {
log::debug!("Closing WebSocket");
}
self.tx = None;
Ok(())
}

/// Forget about this sender without closing the connection.
Expand Down
10 changes: 2 additions & 8 deletions ewebsock/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ pub struct WsSender {

impl Drop for WsSender {
fn drop(&mut self) {
if let Err(err) = self.close() {
log::warn!("Failed to close WebSocket: {err:?}");
}
self.close();
}
}

Expand All @@ -52,14 +50,10 @@ impl WsSender {
/// Close the connection.
///
/// This is called automatically when the sender is dropped.
///
/// # Errors
/// This should never fail, except _maybe_ on Web.
pub fn close(&mut self) -> Result<()> {
pub fn close(&mut self) {
if let Some(socket) = self.socket.take() {
close_socket(&socket);
}
Ok(())
}

/// Forget about this sender without closing the connection.
Expand Down

0 comments on commit ac57008

Please sign in to comment.