1- use crate :: plain;
2- use crate :: error:: { TaskError , RequestError } ;
1+ use crate :: error:: { RequestError , TaskError } ;
32use crate :: handler:: {
4- TaskHandle , client :: Sender , StreamSender , StreamReceiver , Configurator
3+ Configurator , StreamReceiver , StreamSender , TaskHandle , client :: Sender ,
54} ;
65use crate :: packet:: { Packet , PlainBytes } ;
7- use crate :: util:: { PinnedFuture , ByteStream } ;
6+ use crate :: plain;
7+ use crate :: util:: { ByteStream , PinnedFuture } ;
88
99#[ cfg( feature = "encrypted" ) ]
1010use crate :: { encrypted, packet:: EncryptedBytes } ;
1111#[ cfg( feature = "encrypted" ) ]
1212use crypto:: signature as sign;
1313
14- use std:: time:: Duration ;
1514use std:: io;
16-
15+ use std :: time :: Duration ;
1716
1817#[ derive( Debug , Clone ) ]
1918pub struct Config {
2019 pub timeout : Duration ,
2120 /// if the limit is 0 there is no limit
22- pub body_limit : u32
21+ pub body_limit : u32 ,
2322}
2423
2524/// Reconnection strategy
26- ///
25+ ///
2726/// You should probably add a timeout before reconnecting
2827pub struct ReconStrat < S > {
2928 // async fn(error_count: usize) -> io::Result<S>
30- pub ( crate ) inner : Box <
31- dyn FnMut ( usize ) -> PinnedFuture < ' static , io:: Result < S > > + Send
32- >
29+ pub ( crate ) inner :
30+ Box < dyn FnMut ( usize ) -> PinnedFuture < ' static , io:: Result < S > > + Send > ,
3331}
3432
3533impl < S > ReconStrat < S > {
@@ -38,30 +36,30 @@ impl<S> ReconStrat<S> {
3836 /// async fn new_stream(error_count: usize) -> io::Result<S>;
3937 /// ```
4038 pub fn new < F : ' static > ( f : F ) -> Self
41- where F : FnMut ( usize ) -> PinnedFuture < ' static , io :: Result < S > > + Send {
42- Self {
43- inner : Box :: new ( f )
44- }
39+ where
40+ F : FnMut ( usize ) -> PinnedFuture < ' static , io :: Result < S > > + Send ,
41+ {
42+ Self { inner : Box :: new ( f ) }
4543 }
4644}
4745
4846/// A connection to a server
4947pub struct Connection < P > {
5048 sender : Sender < P > ,
51- task : TaskHandle
49+ task : TaskHandle ,
5250}
5351
5452impl < P > Connection < P > {
5553 /// Creates a new connection to a server with an existing stream
5654 pub fn new < S > (
5755 byte_stream : S ,
5856 cfg : Config ,
59- recon_strat : Option < ReconStrat < S > >
57+ recon_strat : Option < ReconStrat < S > > ,
6058 ) -> Self
6159 where
6260 S : ByteStream ,
6361 P : Packet < PlainBytes > + Send + ' static ,
64- P :: Header : Send
62+ P :: Header : Send ,
6563 {
6664 plain:: client ( byte_stream, cfg, recon_strat)
6765 }
@@ -73,12 +71,12 @@ impl<P> Connection<P> {
7371 byte_stream : S ,
7472 cfg : Config ,
7573 recon_strat : Option < ReconStrat < S > > ,
76- sign : sign:: PublicKey
74+ sign : sign:: PublicKey ,
7775 ) -> Self
7876 where
7977 S : ByteStream ,
8078 P : Packet < EncryptedBytes > + Send + ' static ,
81- P :: Header : Send
79+ P :: Header : Send ,
8280 {
8381 encrypted:: client ( byte_stream, cfg, recon_strat, sign)
8482 }
@@ -101,7 +99,7 @@ impl<P> Connection<P> {
10199
102100 /// Send a request waiting until a response is available or the connection
103101 /// closes
104- ///
102+ ///
105103 /// ## Errors
106104 /// - Writing the packet failed
107105 /// - Reading the response packet failed
@@ -113,15 +111,15 @@ impl<P> Connection<P> {
113111 /// Create a new stream to send packets.
114112 pub async fn request_sender (
115113 & self ,
116- packet : P
114+ packet : P ,
117115 ) -> Result < StreamSender < P > , RequestError > {
118116 self . sender . request_sender ( packet) . await
119117 }
120118
121119 /// Opens a new stream to listen to packets.
122120 pub async fn request_receiver (
123121 & self ,
124- packet : P
122+ packet : P ,
125123 ) -> Result < StreamReceiver < P > , RequestError > {
126124 self . sender . request_receiver ( packet) . await
127125 }
@@ -141,4 +139,4 @@ impl<P> Connection<P> {
141139 pub async fn close ( self ) -> Result < ( ) , TaskError > {
142140 self . task . close ( ) . await
143141 }
144- }
142+ }
0 commit comments