syslog_rs/a_sync/async_tokio/
async_mutex.rs

1/*-
2 * syslog-rs - a syslog client translated from libc to rust
3 * 
4 * Copyright 2025 Aleksandr Morozov
5 * 
6 * The syslog-rs crate can be redistributed and/or modified
7 * under the terms of either of the following licenses:
8 *
9 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
10 *                     
11 *   2. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
12 */
13
14use tokio::sync::{Mutex, MutexGuard};
15
16use crate::
17{
18    a_sync::syslog_async_internal::{AsyncMutex, AsyncMutexGuard, AsyncSyslogInternal, AsyncSyslogInternalIO}, 
19    formatters::SyslogFormatter, 
20    AsyncSyslogDestination
21};
22
23
24pub type DefaultAsyncMutex<F, D, IO> = Mutex<AsyncSyslogInternal<F, D, IO>>;
25
26impl<F: SyslogFormatter + Send, D: AsyncSyslogDestination, IO: AsyncSyslogInternalIO> AsyncMutex<F, D, AsyncSyslogInternal<F, D, IO>> 
27for Mutex<AsyncSyslogInternal<F, D, IO>>
28{
29    type MutxGuard<'mux> = MutexGuard<'mux, AsyncSyslogInternal<F, D, IO>>;
30
31    fn a_new(v: AsyncSyslogInternal<F, D, IO>) -> Self 
32    {
33        return Mutex::new(v);
34    }
35    
36    fn a_lock<'mux>(&'mux self) -> impl Future<Output = Self::MutxGuard<'mux>> 
37    {
38        return self.lock();
39    }
40}
41
42impl<'mux, F: SyslogFormatter + Send, D: AsyncSyslogDestination, IO: AsyncSyslogInternalIO> AsyncMutexGuard<'mux, F, D, AsyncSyslogInternal<F, D, IO>>
43for MutexGuard<'mux, AsyncSyslogInternal<F, D, IO>>
44{
45    fn guard(&self) -> &AsyncSyslogInternal<F, D, IO>
46    {
47        return self;
48    }
49
50    fn guard_mut(&mut self) -> &mut AsyncSyslogInternal<F, D, IO>
51    {
52        return self;
53    }
54}