Last active
December 1, 2024 16:28
-
-
Save jberkenbilt/5a8c93fd7977ecf30191ed9caa8d8978 to your computer and use it in GitHub Desktop.
Go to Rust: 04 initial RwLock trait
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::{Deref, DerefMut}; | |
pub trait Runtime: Locker {} | |
/// The [AsyncRwLock::read] and [AsyncRwLock::write] functions must return | |
/// actual async-aware lock guards that maintain the lock until they are out of | |
/// scope. They must not block the thread while holding the lock. | |
pub trait AsyncRwLock<T> { | |
fn new(item: T) -> Self; | |
fn read( | |
&self, | |
) -> impl std::future::Future<Output = impl Deref<Target = T> + Sync + Send> + Send; | |
fn write( | |
&self, | |
) -> impl std::future::Future<Output = impl DerefMut<Target = T> + Sync + Send> + Send; | |
} | |
pub trait Locker { | |
fn new_lock<T: Sync + Send>(item: T) -> impl AsyncRwLock<T>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment