quic_rpc/transport/misc/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Miscellaneous transport utilities

use futures_lite::stream;
use futures_sink::Sink;

use crate::{
    transport::{ConnectionErrors, ServerEndpoint},
    RpcMessage,
};
use std::convert::Infallible;

use super::ConnectionCommon;

/// A dummy server endpoint that does nothing
///
/// This can be useful as a default if you want to configure
/// an optional server endpoint.
#[derive(Debug, Clone, Default)]
pub struct DummyServerEndpoint;

impl ConnectionErrors for DummyServerEndpoint {
    type OpenError = Infallible;
    type RecvError = Infallible;
    type SendError = Infallible;
}

impl<In: RpcMessage, Out: RpcMessage> ConnectionCommon<In, Out> for DummyServerEndpoint {
    type RecvStream = stream::Pending<Result<In, Self::RecvError>>;
    type SendSink = Box<dyn Sink<Out, Error = Self::SendError> + Unpin + Send + Sync>;
}

impl<In: RpcMessage, Out: RpcMessage> ServerEndpoint<In, Out> for DummyServerEndpoint {
    async fn accept(&self) -> Result<(Self::SendSink, Self::RecvStream), Self::OpenError> {
        futures_lite::future::pending().await
    }

    fn local_addr(&self) -> &[super::LocalAddr] {
        &[]
    }
}