@@ -25,6 +25,7 @@ use tonic::transport::Channel;
25
25
26
26
use crate :: load_balance:: { LoadBalance , Loadbalancer } ;
27
27
use crate :: { error, Result } ;
28
+ use derive_builder:: Builder ;
28
29
29
30
const MAX_MESSAGE_SIZE : usize = 512 * 1024 * 1024 ;
30
31
@@ -76,7 +77,8 @@ impl ClientBuilder {
76
77
. load_balance ( self . load_balance )
77
78
. compression ( self . compression )
78
79
. peers ( self . peers )
79
- . build ( ) ;
80
+ . build ( )
81
+ . unwrap ( ) ;
80
82
Client {
81
83
inner : Arc :: new ( inner) ,
82
84
}
@@ -87,7 +89,7 @@ impl ClientBuilder {
87
89
pub enum Compression {
88
90
Gzip ,
89
91
Zstd ,
90
- Plain ,
92
+ None ,
91
93
}
92
94
93
95
impl Default for Compression {
@@ -96,14 +98,22 @@ impl Default for Compression {
96
98
}
97
99
}
98
100
99
- #[ derive( Debug , Default ) ]
101
+ #[ derive( Debug , Default , Builder ) ]
100
102
struct Inner {
101
103
channel_manager : ChannelManager ,
104
+ #[ builder( setter( custom) ) ]
102
105
peers : Arc < RwLock < Vec < String > > > ,
103
106
load_balance : Loadbalancer ,
104
107
compression : Compression ,
105
108
}
106
109
110
+ impl InnerBuilder {
111
+ pub fn peers ( & mut self , peers : Vec < String > ) -> & mut Self {
112
+ self . peers = Some ( Arc :: new ( RwLock :: new ( peers) ) ) ;
113
+ self
114
+ }
115
+ }
116
+
107
117
impl Inner {
108
118
fn set_peers ( & self , peers : Vec < String > ) {
109
119
let mut guard = self . peers . write ( ) ;
@@ -116,45 +126,6 @@ impl Inner {
116
126
}
117
127
}
118
128
119
- #[ derive( Default ) ]
120
- pub struct InnerBuilder {
121
- channel_manager : ChannelManager ,
122
- load_balance : Loadbalancer ,
123
- compression : Compression ,
124
- peers : Arc < RwLock < Vec < String > > > ,
125
- }
126
-
127
- impl InnerBuilder {
128
- pub ( self ) fn channel_manager ( mut self , channel_manager : ChannelManager ) -> Self {
129
- self . channel_manager = channel_manager;
130
- self
131
- }
132
-
133
- pub ( self ) fn load_balance ( mut self , load_balance : Loadbalancer ) -> Self {
134
- self . load_balance = load_balance;
135
- self
136
- }
137
-
138
- pub ( self ) fn compression ( mut self , compression : Compression ) -> Self {
139
- self . compression = compression;
140
- self
141
- }
142
-
143
- pub ( self ) fn peers ( mut self , peers : Vec < String > ) -> Self {
144
- self . peers = Arc :: new ( RwLock :: new ( peers) ) ;
145
- self
146
- }
147
-
148
- pub ( self ) fn build ( self ) -> Inner {
149
- Inner {
150
- channel_manager : self . channel_manager ,
151
- load_balance : self . load_balance ,
152
- compression : self . compression ,
153
- peers : self . peers ,
154
- }
155
- }
156
- }
157
-
158
129
impl Client {
159
130
#[ deprecated( since = "0.1.0" , note = "use `ClientBuilder` instead of this method" ) ]
160
131
pub fn new ( ) -> Self {
@@ -165,7 +136,8 @@ impl Client {
165
136
pub fn with_manager ( channel_manager : ChannelManager ) -> Self {
166
137
let inner = InnerBuilder :: default ( )
167
138
. channel_manager ( channel_manager)
168
- . build ( ) ;
139
+ . build ( )
140
+ . unwrap ( ) ;
169
141
Self {
170
142
inner : Arc :: new ( inner) ,
171
143
}
@@ -189,14 +161,15 @@ impl Client {
189
161
let inner = InnerBuilder :: default ( )
190
162
. channel_manager ( channel_manager)
191
163
. peers ( normailze_urls ( urls) )
192
- . build ( ) ;
164
+ . build ( )
165
+ . unwrap ( ) ;
193
166
194
167
Self {
195
168
inner : Arc :: new ( inner) ,
196
169
}
197
170
}
198
171
199
- #[ deprecated( since = "0.1.0" , note = "should be removed in the future " ) ]
172
+ #[ deprecated( since = "0.1.0" , note = "use `ClientBuilder` instead of this method " ) ]
200
173
pub fn start < U , A > ( & self , urls : A )
201
174
where
202
175
U : AsRef < str > ,
0 commit comments