Skip to content

Commit d9827d3

Browse files
committed
allow to use Result type alias for all results
1 parent b2c0f83 commit d9827d3

File tree

1 file changed

+22
-49
lines changed

1 file changed

+22
-49
lines changed

src/lib.rs

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ pub mod channel {
498498
///
499499
/// If this is a boxed sender that represents a remote connection, sending may yield or fail with an io error.
500500
/// Local senders will never yield, but can fail if the receiver has been closed.
501-
pub async fn send(self, value: T) -> std::result::Result<(), SendError> {
501+
pub async fn send(self, value: T) -> Result<(), SendError> {
502502
match self {
503503
Sender::Tokio(tx) => tx.send(value).map_err(|_| e!(SendError::ReceiverClosed)),
504504
Sender::Boxed(f) => f(value).await,
@@ -569,7 +569,7 @@ pub mod channel {
569569
}
570570

571571
impl<T> Future for Receiver<T> {
572-
type Output = std::result::Result<T, RecvError>;
572+
type Output = Result<T, RecvError>;
573573

574574
fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> task::Poll<Self::Output> {
575575
match self.get_mut() {
@@ -814,14 +814,7 @@ pub mod channel {
814814
pub trait DynReceiver<T>: Debug + Send + Sync + 'static {
815815
fn recv(
816816
&mut self,
817-
) -> Pin<
818-
Box<
819-
dyn Future<Output = std::result::Result<Option<T>, RecvError>>
820-
+ Send
821-
+ Sync
822-
+ '_,
823-
>,
824-
>;
817+
) -> Pin<Box<dyn Future<Output = Result<Option<T>, RecvError>> + Send + Sync + '_>>;
825818
}
826819

827820
impl<T> Debug for Sender<T> {
@@ -846,7 +839,7 @@ pub mod channel {
846839
/// then the sender will be closed and further sends will return an [`SendError::Io`]
847840
/// with [`std::io::ErrorKind::BrokenPipe`]. Therefore, make sure to always poll the
848841
/// future until completion if you want to reuse the sender or any clone afterwards.
849-
pub async fn send(&self, value: T) -> std::result::Result<(), SendError> {
842+
pub async fn send(&self, value: T) -> Result<(), SendError> {
850843
match self {
851844
Sender::Tokio(tx) => tx
852845
.send(value)
@@ -877,7 +870,7 @@ pub mod channel {
877870
/// then the sender will be closed and further sends will return an [`SendError::Io`]
878871
/// with [`std::io::ErrorKind::BrokenPipe`]. Therefore, make sure to always poll the
879872
/// future until completion if you want to reuse the sender or any clone afterwards.
880-
pub async fn try_send(&self, value: T) -> std::result::Result<bool, SendError> {
873+
pub async fn try_send(&self, value: T) -> Result<bool, SendError> {
881874
match self {
882875
Sender::Tokio(tx) => match tx.try_send(value) {
883876
Ok(()) => Ok(true),
@@ -906,7 +899,7 @@ pub mod channel {
906899
/// cleanly closed the connection.
907900
///
908901
/// Returns an an io error if there was an error receiving the message.
909-
pub async fn recv(&mut self) -> std::result::Result<Option<T>, RecvError> {
902+
pub async fn recv(&mut self) -> Result<Option<T>, RecvError> {
910903
match self {
911904
Self::Tokio(rx) => Ok(rx.recv().await),
912905
Self::Boxed(rx) => Ok(rx.recv().await?),
@@ -951,7 +944,7 @@ pub mod channel {
951944
#[cfg(feature = "stream")]
952945
pub fn into_stream(
953946
self,
954-
) -> impl n0_future::Stream<Item = std::result::Result<T, RecvError>> + Send + Sync + 'static
947+
) -> impl n0_future::Stream<Item = Result<T, RecvError>> + Send + Sync + 'static
955948
{
956949
n0_future::stream::unfold(self, |mut recv| async move {
957950
recv.recv().await.transpose().map(|msg| (msg, recv))
@@ -1069,14 +1062,8 @@ pub mod channel {
10691062
{
10701063
fn recv(
10711064
&mut self,
1072-
) -> Pin<
1073-
Box<
1074-
dyn Future<Output = std::result::Result<Option<U>, RecvError>>
1075-
+ Send
1076-
+ Sync
1077-
+ '_,
1078-
>,
1079-
> {
1065+
) -> Pin<Box<dyn Future<Output = Result<Option<U>, RecvError>> + Send + Sync + '_>>
1066+
{
10801067
Box::pin(async move {
10811068
while let Some(msg) = self.receiver.recv().await? {
10821069
if let Some(v) = (self.f)(msg) {
@@ -1345,9 +1332,7 @@ impl<S: Service> Client<S> {
13451332
#[allow(clippy::type_complexity)]
13461333
pub fn request(
13471334
&self,
1348-
) -> impl Future<
1349-
Output = result::Result<Request<LocalSender<S>, rpc::RemoteSender<S>>, RequestError>,
1350-
>
1335+
) -> impl Future<Output = Result<Request<LocalSender<S>, rpc::RemoteSender<S>>, RequestError>>
13511336
+ 'static
13521337
+ use<S> {
13531338
#[cfg(feature = "rpc")]
@@ -1768,7 +1753,7 @@ pub enum Error {
17681753
}
17691754

17701755
/// Type alias for a result with an irpc error type.
1771-
pub type Result<T> = std::result::Result<T, Error>;
1756+
pub type Result<T, E = Error> = std::result::Result<T, E>;
17721757

17731758
impl From<Error> for io::Error {
17741759
fn from(e: Error) -> Self {
@@ -1946,7 +1931,7 @@ pub mod rpc {
19461931
/// Open a bidirectional stream to the remote service.
19471932
fn open_bi(
19481933
&self,
1949-
) -> BoxFuture<std::result::Result<(quinn::SendStream, quinn::RecvStream), RequestError>>;
1934+
) -> BoxFuture<Result<(quinn::SendStream, quinn::RecvStream), RequestError>>;
19501935

19511936
/// Returns whether 0-RTT data was accepted by the server.
19521937
///
@@ -1975,8 +1960,7 @@ pub mod rpc {
19751960

19761961
fn open_bi(
19771962
&self,
1978-
) -> BoxFuture<std::result::Result<(quinn::SendStream, quinn::RecvStream), RequestError>>
1979-
{
1963+
) -> BoxFuture<Result<(quinn::SendStream, quinn::RecvStream), RequestError>> {
19801964
let conn = self.clone();
19811965
Box::pin(async move {
19821966
let pair = conn.open_bi().await?;
@@ -2006,8 +1990,7 @@ pub mod rpc {
20061990

20071991
fn open_bi(
20081992
&self,
2009-
) -> BoxFuture<std::result::Result<(quinn::SendStream, quinn::RecvStream), RequestError>>
2010-
{
1993+
) -> BoxFuture<Result<(quinn::SendStream, quinn::RecvStream), RequestError>> {
20111994
let this = self.0.clone();
20121995
Box::pin(async move {
20131996
let mut guard = this.connection.lock().await;
@@ -2055,7 +2038,7 @@ pub mod rpc {
20552038

20562039
pub(crate) fn prepare_write<S: Service>(
20572040
msg: impl Into<S>,
2058-
) -> std::result::Result<SmallVec<[u8; 128]>, WriteError> {
2041+
) -> Result<SmallVec<[u8; 128]>, WriteError> {
20592042
let msg = msg.into();
20602043
if postcard::experimental::serialized_size(&msg)? as u64 > MAX_MESSAGE_SIZE {
20612044
return Err(e!(WriteError::MaxMessageSizeExceeded));
@@ -2073,15 +2056,15 @@ pub mod rpc {
20732056
pub async fn write(
20742057
self,
20752058
msg: impl Into<S>,
2076-
) -> std::result::Result<(quinn::SendStream, quinn::RecvStream), WriteError> {
2059+
) -> Result<(quinn::SendStream, quinn::RecvStream), WriteError> {
20772060
let buf = prepare_write(msg)?;
20782061
self.write_raw(&buf).await
20792062
}
20802063

20812064
pub(crate) async fn write_raw(
20822065
self,
20832066
buf: &[u8],
2084-
) -> std::result::Result<(quinn::SendStream, quinn::RecvStream), WriteError> {
2067+
) -> Result<(quinn::SendStream, quinn::RecvStream), WriteError> {
20852068
let RemoteSender(mut send, recv, _) = self;
20862069
send.write_all(buf).await?;
20872070
Ok((send, recv))
@@ -2193,14 +2176,8 @@ pub mod rpc {
21932176
impl<T: RpcMessage> DynReceiver<T> for QuinnReceiver<T> {
21942177
fn recv(
21952178
&mut self,
2196-
) -> Pin<
2197-
Box<
2198-
dyn Future<Output = std::result::Result<Option<T>, mpsc::RecvError>>
2199-
+ Send
2200-
+ Sync
2201-
+ '_,
2202-
>,
2203-
> {
2179+
) -> Pin<Box<dyn Future<Output = Result<Option<T>, mpsc::RecvError>> + Send + Sync + '_>>
2180+
{
22042181
Box::pin(async {
22052182
let read = &mut self.recv;
22062183
let Some(size) = read.read_varint_u64().await? else {
@@ -2373,11 +2350,7 @@ pub mod rpc {
23732350

23742351
/// Type alias for a handler fn for remote requests
23752352
pub type Handler<R> = Arc<
2376-
dyn Fn(
2377-
R,
2378-
quinn::RecvStream,
2379-
quinn::SendStream,
2380-
) -> BoxFuture<std::result::Result<(), SendError>>
2353+
dyn Fn(R, quinn::RecvStream, quinn::SendStream) -> BoxFuture<Result<(), SendError>>
23812354
+ Send
23822355
+ Sync
23832356
+ 'static,
@@ -2529,7 +2502,7 @@ impl<S: Service> LocalSender<S> {
25292502
pub fn send<T>(
25302503
&self,
25312504
value: impl Into<WithChannels<T, S>>,
2532-
) -> impl Future<Output = std::result::Result<(), SendError>> + Send + 'static
2505+
) -> impl Future<Output = Result<(), SendError>> + Send + 'static
25332506
where
25342507
T: Channels<S>,
25352508
S::Message: From<WithChannels<T, S>>,
@@ -2542,7 +2515,7 @@ impl<S: Service> LocalSender<S> {
25422515
pub fn send_raw(
25432516
&self,
25442517
value: S::Message,
2545-
) -> impl Future<Output = std::result::Result<(), SendError>> + Send + 'static + use<S> {
2518+
) -> impl Future<Output = Result<(), SendError>> + Send + 'static + use<S> {
25462519
let x = self.0.clone();
25472520
async move { x.send(value).await }
25482521
}

0 commit comments

Comments
 (0)