Skip to content

Commit

Permalink
Use io::Error instead of SendError
Browse files Browse the repository at this point in the history
  • Loading branch information
msk committed May 10, 2024
1 parent 29ad689 commit 3571f1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ where
///
/// # Errors
///
/// * `SendError::MessageTooLarge`: if the message is too large
/// * `SendError::WriteError`: if the message could not be written
pub async fn send_raw(send: &mut SendStream, buf: &[u8]) -> Result<(), SendError> {
let len = u32::try_from(buf.len()).map_err(|_| SendError::MessageTooLarge)?;
/// Returns an error if the message is too large or could not be written.
pub async fn send_raw(send: &mut SendStream, buf: &[u8]) -> io::Result<()> {
let len =
u32::try_from(buf.len()).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
send.write_all(&len.to_be_bytes()).await?;
send.write_all(buf).await?;
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn send_request<C, B>(
buf: &mut Vec<u8>,
code: C,
body: B,
) -> Result<(), SendError>
) -> io::Result<()>
where
C: Into<u32>,
B: Serialize,
Expand All @@ -57,7 +57,7 @@ where
buf.extend_from_slice(&code.into().to_le_bytes());
bincode::DefaultOptions::new()
.serialize_into(buf as &mut dyn Write, &body)
.map_err(|_| SendError::MessageTooLarge)?;
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
frame::send_raw(send, buf).await?;
buf.clear();
Ok(())
Expand Down

0 comments on commit 3571f1d

Please sign in to comment.