drifter 0.1.11

A TUI-based S3 multipart uploader featuring resumable transfers and ClamAV integration.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use anyhow::Result;
use std::sync::{Mutex, MutexGuard};
use tokio::sync::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard};

/// Lock a mutex and return a Result.
/// Finds poison errors and returns them as Anyhow errors.
pub fn lock_mutex<T>(mutex: &Mutex<T>) -> Result<MutexGuard<'_, T>> {
    mutex
        .lock()
        .map_err(|e| anyhow::anyhow!("Mutex poisoned: {}", e))
}

/// Lock an async mutex and return the guard.
/// Tokio mutexes don't poison, so this just awaits.
pub async fn lock_async_mutex<T>(mutex: &AsyncMutex<T>) -> AsyncMutexGuard<'_, T> {
    mutex.lock().await
}