use std::sync::Arc; use axum::async_trait; use tokio::sync::Mutex; #[derive(Clone)] pub struct LeaseService(Arc); impl std::ops::Deref for LeaseService { type Target = Arc; fn deref(&self) -> &Self::Target { &self.0 } } impl Default for LeaseService { fn default() -> Self { Self(Arc::new(DefaultLeaseService::default())) } } #[derive(Default)] struct DefaultLeaseService { leases: Arc>>, } #[async_trait] pub trait LeaseServiceTrait { async fn create_lease(&self) -> anyhow::Result; } #[async_trait] impl LeaseServiceTrait for DefaultLeaseService { async fn create_lease(&self) -> anyhow::Result { let mut leases = self.leases.lock().await; let lease = uuid::Uuid::new_v4().to_string(); leases.push(lease.clone()); Ok(lease) } }