dlock 0.2.0

A lease based distributed lock with support for fencing tokens
Documentation
// SPDX-FileCopyrightText: 2025 Abe Kohandel <abe@kodebooth.com>
// SPDX-License-Identifier: MIT

use std::{fmt::Debug, time::Duration};

use crate::error::DLockError;

#[cfg(feature = "dynamodb")]
pub mod dynamodb;

/// `Provider` is a trait that abstracts the backend specific details of the
/// lock acquisition mechanism.
#[trait_variant::make(Provider: Send)]
pub trait LocalProvider: Clone {
    type T;
    type L: Lease<Self::L, Self::T>;
    type R: Clone;

    async fn acquire(
        &self,
        name: &str,
        owner: &str,
        duration: &Duration,
        retry: Option<Self::R>,
    ) -> Result<Self::L, DLockError<Self::R>>;
}

/// `Lease` is a trait that abstracts the backend specific details of the
/// lock renewal and release mechanism.
#[trait_variant::make(Lease: Send)]
pub trait LocalLease<L, T>: Debug {
    async fn release(&self) -> Result<(), DLockError>;
    async fn renew(&self) -> Result<L, DLockError>;

    fn token(&self) -> T;
}