two-way file system sync
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

client.rs 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. use futures::Future;
  2. use futures::task::{Context, Poll};
  3. use core::pin::Pin;
  4. use tokio::stream::Stream;
  5. use async_tungstenite::{tokio::connect_async, tungstenite::Message, WebSocketStream};
  6. use url::Url;
  7. use super::packet_connection::IncomingPacket;
  8. use std::time::Duration;
  9. pub trait RPCInterface {
  10. type PacketType;
  11. type NetworkError;
  12. type Call: RPC<Output = Result<IncomingPacket<Self::PacketType>, Self::NetworkError>>;
  13. fn call(call: &Self::PacketType) -> Self::Call;
  14. }
  15. pub trait RPC: Future {
  16. fn with_timeout(self, timeout: Duration) -> Self;
  17. }
  18. pub trait ServerEventStream<PacketType>: Stream<Item = PacketType> {}
  19. pub struct WSRPCInterface<PacketType, Stream> {
  20. // TODO
  21. _unused: PacketType,
  22. stream: WebSocketStream<Stream>,
  23. }
  24. impl<P, S> WSRPCInterface<P, S> {
  25. fn create<P2, S2>(ws_stream: WebSocketStream<S2>) -> (Self, WSServerEventStream<P2>) {
  26. // TODO
  27. panic!("Not yet implemented.");
  28. }
  29. }
  30. impl<P, S> RPCInterface for WSRPCInterface<P, S> {
  31. type PacketType = P;
  32. type NetworkError = String; // TODO
  33. type Call = WSRPC<Self::PacketType>;
  34. fn call(call: &Self::PacketType) -> Self::Call {
  35. // TODO
  36. panic!("Not yet implemented.");
  37. }
  38. }
  39. pub struct WSRPC<PacketType> {
  40. // TODO
  41. _unused: PacketType,
  42. }
  43. impl<P> Future for WSRPC<P> {
  44. type Output = Result<IncomingPacket<P>, String>;
  45. fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
  46. // TODO
  47. panic!("Not yet implemented.");
  48. }
  49. }
  50. impl<P> RPC for WSRPC<P> {
  51. fn with_timeout(self, timeout: Duration) -> Self {
  52. // TODO
  53. panic!("Not yet implemented.");
  54. }
  55. }
  56. struct WSServerEventStream<PacketType> {
  57. _unused: PacketType,
  58. }
  59. impl<P> Stream for WSServerEventStream<P> {
  60. type Item = P;
  61. fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
  62. // TODO
  63. panic!("Not yet implemented.");
  64. }
  65. }
  66. pub async fn low_level_integration_test_client(address: String) {
  67. let url = Url::parse(&address).unwrap();
  68. let (mut ws_stream, _) = connect_async(url).await.unwrap();
  69. // TODO
  70. }