mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-04-30 02:38:01 +00:00
cargo fmt
This commit is contained in:
@@ -5,21 +5,22 @@ use tokio::net::TcpStream;
|
||||
use tokio_util::compat::TokioAsyncReadCompatExt;
|
||||
|
||||
use super::{
|
||||
sender::{ Sender, SentMessage, SentMessageInternal },
|
||||
receiver::{ Receiver, RecvMessage }
|
||||
receiver::{Receiver, RecvMessage},
|
||||
sender::{Sender, SentMessage, SentMessageInternal},
|
||||
};
|
||||
|
||||
/// The send side of a Soketto WebSocket connection
|
||||
pub type RawSender = soketto::connection::Sender<tokio_util::compat::Compat<tokio::net::TcpStream>>;
|
||||
|
||||
/// The receive side of a Soketto WebSocket connection
|
||||
pub type RawReceiver = soketto::connection::Receiver<tokio_util::compat::Compat<tokio::net::TcpStream>>;
|
||||
pub type RawReceiver =
|
||||
soketto::connection::Receiver<tokio_util::compat::Compat<tokio::net::TcpStream>>;
|
||||
|
||||
/// A websocket connection. From this, we can either expose the raw connection
|
||||
/// or expose a cancel-safe interface to it.
|
||||
pub struct Connection {
|
||||
tx: soketto::connection::Sender<tokio_util::compat::Compat<tokio::net::TcpStream>>,
|
||||
rx: soketto::connection::Receiver<tokio_util::compat::Compat<tokio::net::TcpStream>>
|
||||
rx: soketto::connection::Receiver<tokio_util::compat::Compat<tokio::net::TcpStream>>,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
@@ -109,7 +110,7 @@ impl Connection {
|
||||
);
|
||||
break;
|
||||
}
|
||||
},
|
||||
}
|
||||
SentMessageInternal::Message(SentMessage::StaticText(s)) => {
|
||||
if let Err(e) = ws_to_connection.send_text(s).await {
|
||||
log::error!(
|
||||
@@ -127,7 +128,7 @@ impl Connection {
|
||||
);
|
||||
break;
|
||||
}
|
||||
},
|
||||
}
|
||||
SentMessageInternal::Close => {
|
||||
if let Err(e) = ws_to_connection.close().await {
|
||||
log::error!("Error attempting to close connection: {}", e);
|
||||
@@ -185,6 +186,6 @@ pub async fn connect(uri: &http::Uri) -> Result<Connection, ConnectError> {
|
||||
|
||||
Ok(Connection {
|
||||
tx: ws_to_connection,
|
||||
rx: ws_from_connection
|
||||
rx: ws_from_connection,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/// Functionality to establish a connection
|
||||
mod connect;
|
||||
/// The channel based send interface
|
||||
mod sender;
|
||||
/// The channel based receive interface
|
||||
mod receiver;
|
||||
/// The channel based send interface
|
||||
mod sender;
|
||||
|
||||
pub use connect::{ connect, ConnectError, Connection, RawSender, RawReceiver };
|
||||
pub use sender::{ Sender, SentMessage, SendError };
|
||||
pub use receiver::{ Receiver, RecvMessage, RecvError };
|
||||
pub use connect::{connect, ConnectError, Connection, RawReceiver, RawSender};
|
||||
pub use receiver::{Receiver, RecvError, RecvMessage};
|
||||
pub use sender::{SendError, Sender, SentMessage};
|
||||
|
||||
@@ -3,7 +3,7 @@ use futures::{Stream, StreamExt};
|
||||
|
||||
/// Receive messages out of a connection
|
||||
pub struct Receiver {
|
||||
pub (super) inner: mpsc::UnboundedReceiver<Result<RecvMessage, RecvError>>,
|
||||
pub(super) inner: mpsc::UnboundedReceiver<Result<RecvMessage, RecvError>>,
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
@@ -40,4 +40,4 @@ impl RecvMessage {
|
||||
RecvMessage::Text(s) => s.len(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pub enum SentMessage {
|
||||
|
||||
/// Messages sent into the channel interface can be anything publically visible, or a close message.
|
||||
#[derive(Debug, Clone)]
|
||||
pub (super) enum SentMessageInternal {
|
||||
pub(super) enum SentMessageInternal {
|
||||
Message(SentMessage),
|
||||
Close,
|
||||
}
|
||||
@@ -30,7 +30,7 @@ pub (super) enum SentMessageInternal {
|
||||
/// Send messages into the connection
|
||||
#[derive(Clone)]
|
||||
pub struct Sender {
|
||||
pub (super) inner: mpsc::UnboundedSender<SentMessageInternal>,
|
||||
pub(super) inner: mpsc::UnboundedSender<SentMessageInternal>,
|
||||
}
|
||||
|
||||
impl Sender {
|
||||
@@ -56,7 +56,7 @@ impl Sender {
|
||||
#[derive(thiserror::Error, Debug, Clone)]
|
||||
pub enum SendError {
|
||||
#[error("Failed to send message: {0}")]
|
||||
ChannelError(#[from] mpsc::SendError)
|
||||
ChannelError(#[from] mpsc::SendError),
|
||||
}
|
||||
|
||||
impl Sink<SentMessage> for Sender {
|
||||
@@ -67,7 +67,10 @@ impl Sink<SentMessage> for Sender {
|
||||
) -> std::task::Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_ready_unpin(cx).map_err(|e| e.into())
|
||||
}
|
||||
fn start_send(mut self: std::pin::Pin<&mut Self>, item: SentMessage) -> Result<(), Self::Error> {
|
||||
fn start_send(
|
||||
mut self: std::pin::Pin<&mut Self>,
|
||||
item: SentMessage,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.inner
|
||||
.start_send_unpin(SentMessageInternal::Message(item))
|
||||
.map_err(|e| e.into())
|
||||
@@ -84,4 +87,4 @@ impl Sink<SentMessage> for Sender {
|
||||
) -> std::task::Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_close_unpin(cx).map_err(|e| e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user