Skip to content

Instantly share code, notes, and snippets.

@jberkenbilt
Last active December 1, 2024 16:28
Show Gist options
  • Save jberkenbilt/5a8c93fd7977ecf30191ed9caa8d8978 to your computer and use it in GitHub Desktop.
Save jberkenbilt/5a8c93fd7977ecf30191ed9caa8d8978 to your computer and use it in GitHub Desktop.
Go to Rust: 04 initial RwLock trait
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