Struct SyncClient
pub struct SyncClient {
api_configurations: Arc<ApiConfigurations>,
sync_handlers: HandlerRegistry<dyn SyncHandler>,
error_handlers: HandlerRegistry<dyn SyncErrorHandler>,
sync_lock: Mutex<()>,
last_sync: Option<Setting<DateTime<Utc>>>,
}Expand description
Client for performing sync operations with event support
This client wraps the core sync functionality and provides hooks for registering event handlers that can respond to sync operations.
Fields§
§api_configurations: Arc<ApiConfigurations>§sync_handlers: HandlerRegistry<dyn SyncHandler>§error_handlers: HandlerRegistry<dyn SyncErrorHandler>§sync_lock: Mutex<()>§last_sync: Option<Setting<DateTime<Utc>>>Implementations§
§impl SyncClient
impl SyncClient
pub fn new(client: Client) -> SyncClient
pub fn new(client: Client) -> SyncClient
Create a new SyncClient from a Bitwarden client
pub async fn last_sync(&self) -> Option<DateTime<Utc>>
pub async fn last_sync(&self) -> Option<DateTime<Utc>>
Get the timestamp of the last successful sync or confirmed-up-to-date skip, if any.
pub fn register_sync_handler(&self, handler: Arc<dyn SyncHandler>)
pub fn register_sync_handler(&self, handler: Arc<dyn SyncHandler>)
Register a sync handler for sync operations
Handlers are called in registration order. If any handler returns an error, the sync operation is aborted immediately and subsequent handlers are not called.
pub fn register_error_handler(&self, handler: Arc<dyn SyncErrorHandler>)
pub fn register_error_handler(&self, handler: Arc<dyn SyncErrorHandler>)
Register an error handler for sync operations
Error handlers are called when any error occurs during sync, including API errors and handler errors. All error handlers are always called regardless of individual failures.
pub async fn sync(&self, request: SyncRequest) -> Result<bool, SyncError>
pub async fn sync(&self, request: SyncRequest) -> Result<bool, SyncError>
Perform a sync operation, skipping the server call when nothing has changed.
Returns Ok(true) if a full sync was performed, or Ok(false) if the revision-date
check determined that the server has no new changes and the sync was skipped.
§Control flow
Unless request.force is true, this method first fetches the account revision date
from the server and compares it to the stored last_sync timestamp. If the revision
is not newer, the sync is skipped: last_sync is bumped to now and Ok(false) is
returned without calling any sync or error handlers.
When a full sync is performed:
- Fetches the full sync response from the Bitwarden API.
- Dispatches
on_syncwith the response to all registered handlers in order; stops on the first handler error. - Dispatches
on_sync_completeto all handlers for post-processing. - On success, bumps
last_syncto now and returnsOk(true).
§Errors
Any error (revision-date fetch, API call, or handler failure) is forwarded to all
registered error handlers before being returned to the caller. last_sync is never
bumped on an error path.
Auto Trait Implementations§
impl !Freeze for SyncClient
impl !RefUnwindSafe for SyncClient
impl Send for SyncClient
impl Sync for SyncClient
impl Unpin for SyncClient
impl UnsafeUnpin for SyncClient
impl !UnwindSafe for SyncClient
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more