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. The MIT License (MIT)
12 *                     
13 *   3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
14 */
15
16use tokio::sync::{Mutex, MutexGuard};
17
18use crate::
19{
20    a_sync::syslog_async_internal::{AsyncMutex, AsyncMutexGuard, AsyncSyslogInternal, AsyncSyslogInternalIO}, 
21    formatters::SyslogFormatter, 
22    AsyncSyslogDestination
23};
24
25
26pub type DefaultAsyncMutex<F, D, IO> = Mutex<AsyncSyslogInternal<F, D, IO>>;
27
28impl<F: SyslogFormatter + Send, D: AsyncSyslogDestination, IO: AsyncSyslogInternalIO> AsyncMutex<F, D, AsyncSyslogInternal<F, D, IO>> 
29for Mutex<AsyncSyslogInternal<F, D, IO>>
30{
31    type MutxGuard<'mux> = MutexGuard<'mux, AsyncSyslogInternal<F, D, IO>>;
32
33    fn a_new(v: AsyncSyslogInternal<F, D, IO>) -> Self 
34    {
35        return Mutex::new(v);
36    }
37    
38    fn a_lock<'mux>(&'mux self) -> impl Future<Output = Self::MutxGuard<'mux>> 
39    {
40        return self.lock();
41    }
42}
43
44impl<'mux, F: SyslogFormatter + Send, D: AsyncSyslogDestination, IO: AsyncSyslogInternalIO> AsyncMutexGuard<'mux, F, D, AsyncSyslogInternal<F, D, IO>>
45for MutexGuard<'mux, AsyncSyslogInternal<F, D, IO>>
46{
47    fn guard(&self) -> &AsyncSyslogInternal<F, D, IO>
48    {
49        return self;
50    }
51
52    fn guard_mut(&mut self) -> &mut AsyncSyslogInternal<F, D, IO>
53    {
54        return self;
55    }
56}