@@ -67,6 +67,7 @@ impl Builder<()> {
67
67
http_request_callback: None ,
68
68
namespace: None ,
69
69
skip_safety_assert: false ,
70
+ #[ cfg( feature = "sync" ) ]
70
71
sync_protocol: Default :: default ( ) ,
71
72
} ,
72
73
}
@@ -223,6 +224,7 @@ cfg_replication! {
223
224
http_request_callback: Option <crate :: util:: HttpRequestCallback >,
224
225
namespace: Option <String >,
225
226
skip_safety_assert: bool ,
227
+ #[ cfg( feature = "sync" ) ]
226
228
sync_protocol: super :: SyncProtocol ,
227
229
}
228
230
@@ -279,6 +281,7 @@ cfg_replication! {
279
281
/// Set the duration at which the replicator will automatically call `sync` in the
280
282
/// background. The sync will continue for the duration that the resulted `Database`
281
283
/// type is alive for, once it is dropped the background task will get dropped and stop.
284
+ #[ cfg( feature = "sync" ) ]
282
285
pub fn sync_protocol( mut self , protocol: super :: SyncProtocol ) -> Builder <RemoteReplica > {
283
286
self . inner. sync_protocol = protocol;
284
287
self
@@ -337,6 +340,7 @@ cfg_replication! {
337
340
http_request_callback,
338
341
namespace,
339
342
skip_safety_assert,
343
+ #[ cfg( feature = "sync" ) ]
340
344
sync_protocol,
341
345
} = self . inner;
342
346
@@ -353,44 +357,46 @@ cfg_replication! {
353
357
crate :: util:: ConnectorService :: new( svc)
354
358
} ;
355
359
356
- use super :: SyncProtocol ;
357
-
358
- match sync_protocol {
359
- p @ ( SyncProtocol :: Auto | SyncProtocol :: V2 ) => {
360
- let client = hyper:: client:: Client :: builder( )
361
- . build:: <_, hyper:: Body >( connector. clone( ) ) ;
362
-
363
- let req = http:: Request :: get( format!( "{url}/sync/0/0/0" ) )
364
- . header( "Authorization" , format!( "Bearer {}" , auth_token) )
365
- . body( hyper:: Body :: empty( ) )
366
- . unwrap( ) ;
367
-
368
- let res = client
369
- . request( req)
370
- . await
371
- . map_err( |err| crate :: Error :: Sync ( err. into( ) ) ) ?;
372
-
373
- if matches!( p, SyncProtocol :: V2 ) {
374
- if !res. status( ) . is_success( ) {
375
- let status = res. status( ) ;
376
- let body_bytes = hyper:: body:: to_bytes( res. into_body( ) )
377
- . await
378
- . map_err( |err| crate :: Error :: Sync ( err. into( ) ) ) ?;
379
- let error_message = String :: from_utf8_lossy( & body_bytes) ;
380
- return Err ( crate :: Error :: Sync ( format!( "HTTP error {}: {}" , status, error_message) . into( ) ) ) ;
360
+ #[ cfg( feature = "sync" ) ]
361
+ {
362
+ use super :: SyncProtocol ;
363
+ match sync_protocol {
364
+ p @ ( SyncProtocol :: Auto | SyncProtocol :: V2 ) => {
365
+ let client = hyper:: client:: Client :: builder( )
366
+ . build:: <_, hyper:: Body >( connector. clone( ) ) ;
367
+
368
+ let req = http:: Request :: get( format!( "{url}/sync/0/0/0" ) )
369
+ . header( "Authorization" , format!( "Bearer {}" , auth_token) )
370
+ . body( hyper:: Body :: empty( ) )
371
+ . unwrap( ) ;
372
+
373
+ let res = client
374
+ . request( req)
375
+ . await
376
+ . map_err( |err| crate :: Error :: Sync ( err. into( ) ) ) ?;
377
+
378
+ if matches!( p, SyncProtocol :: V2 ) {
379
+ if !res. status( ) . is_success( ) {
380
+ let status = res. status( ) ;
381
+ let body_bytes = hyper:: body:: to_bytes( res. into_body( ) )
382
+ . await
383
+ . map_err( |err| crate :: Error :: Sync ( err. into( ) ) ) ?;
384
+ let error_message = String :: from_utf8_lossy( & body_bytes) ;
385
+ return Err ( crate :: Error :: Sync ( format!( "HTTP error {}: {}" , status, error_message) . into( ) ) ) ;
386
+ }
381
387
}
382
- }
383
388
384
- if res. status( ) . is_success( ) {
385
- return Builder :: new_synced_database( path, url, auth_token)
386
- . remote_writes( true )
387
- . read_your_writes( read_your_writes)
388
- . build( )
389
- . await ;
390
- }
389
+ if res. status( ) . is_success( ) {
390
+ return Builder :: new_synced_database( path, url, auth_token)
391
+ . remote_writes( true )
392
+ . read_your_writes( read_your_writes)
393
+ . build( )
394
+ . await ;
395
+ }
391
396
397
+ }
398
+ SyncProtocol :: V1 => { }
392
399
}
393
- SyncProtocol :: V1 => { }
394
400
}
395
401
396
402
let path = path. to_str( ) . ok_or( crate :: Error :: InvalidUTF8Path ) ?. to_owned( ) ;
0 commit comments