transport.rs 892 B

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