transport.rs 937 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. use std::error::Error;
  2. use async_trait::async_trait;
  3. use futures::prelude::*;
  4. use url::Url;
  5. mod tcp;
  6. mod tls;
  7. mod tor;
  8. pub use tcp::TcpTransport;
  9. pub use tls::TlsTransport;
  10. pub use tor::TorTransport;
  11. #[async_trait]
  12. pub trait Transport {
  13. type Acceptor;
  14. type Connector;
  15. type Error: Error;
  16. type Listener: Future<Output = Result<Self::Acceptor, Self::Error>>;
  17. type Dial: Future<Output = Result<Self::Connector, Self::Error>>;
  18. fn listen_on(self, url: Url) -> Result<Self::Listener, TransportError<Self::Error>>
  19. where
  20. Self: Sized;
  21. fn dial(self, url: Url) -> Result<Self::Dial, TransportError<Self::Error>>
  22. where
  23. Self: Sized;
  24. }
  25. #[derive(Debug, thiserror::Error)]
  26. pub enum TransportError<TErr> {
  27. #[error("Address not supported: {0}")]
  28. AddrNotSupported(Url),
  29. #[error("Transport IO Error: {0}")]
  30. IoError(#[from] std::io::Error),
  31. #[error("{0}")]
  32. Other(TErr),
  33. }