Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
abezukor committed Jun 14, 2024
1 parent 5c60d1a commit cf6ff29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/bluer/l2cap_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use std::{
io::Result,
pin::Pin,
task::{Context, Poll},
time::Duration,
};

use bluer::l2cap::{SocketAddr, Stream};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tracing::{debug, trace};
use tracing::trace;

use crate::error::ErrorKind;

Expand All @@ -19,10 +18,8 @@ pub struct Channel {
}

enum ChannelCreationError {
StreamCreationError(std::io::Error),
SetSecurityError(std::io::Error),
ConnectionError(std::io::Error),
ConnectionTimeout(tokio::time::error::Elapsed),
}

impl Channel {
Expand Down Expand Up @@ -80,27 +77,19 @@ impl AsyncWrite for Channel {
impl From<ChannelCreationError> for crate::Error {
fn from(value: ChannelCreationError) -> Self {
let kind = match &value {
ChannelCreationError::StreamCreationError(_) | ChannelCreationError::SetSecurityError(_) => {
ErrorKind::Internal
}
ChannelCreationError::SetSecurityError(_) => ErrorKind::Internal,
ChannelCreationError::ConnectionError(_) => ErrorKind::ConnectionFailed,
ChannelCreationError::ConnectionTimeout(_) => ErrorKind::Timeout,
};
let message = match &value {
ChannelCreationError::StreamCreationError(_) => "Error creating a new l2cap stream.",
ChannelCreationError::SetSecurityError(_) => "Error setting connection security level.",
ChannelCreationError::ConnectionError(_) => "Error connecting to l2cap stream.",
ChannelCreationError::ConnectionTimeout(_) => {
"Timeout occured before stream parameters could be determined."
}
};
crate::Error::new(
kind,
match value {
ChannelCreationError::StreamCreationError(io)
| ChannelCreationError::SetSecurityError(io)
| ChannelCreationError::ConnectionError(io) => Some(Box::new(io)),
ChannelCreationError::ConnectionTimeout(elapsed) => Some(Box::new(elapsed)),
ChannelCreationError::SetSecurityError(io) | ChannelCreationError::ConnectionError(io) => {
Some(Box::new(io))
}
},
message.to_owned(),
)
Expand Down
2 changes: 2 additions & 0 deletions src/corebluetooth/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ pub(super) unsafe trait NSStream: Sized + Message {
}
}

/// # Safety
/// Only implement for objective C object that inherit from CFStream (https://developer.apple.com/documentation/corefoundation/cfstream)
pub(super) unsafe trait CFStream: Sized + Message {
fn property(&self, key: &id) -> Option<&NSData> {
let key = unsafe { extern_nsstring(*key) };
Expand Down

0 comments on commit cf6ff29

Please sign in to comment.