frugal_async 0.1.0

A crate of utilities for frugally working with async code
Documentation
//! This crate provides utilities for writing async Rust code. Unlike many other such crates, it makes a couple of simplifying assumptions:
//!
//! - no cancel-safety required,
//! - futures need not be [`Send`], and
//! - panics always abort the program.
//!
//! See [Frugal Async Rust](https://worm-blossom.org/frugal_async_rust.html) for more details on these assumptions.
//!
//! ## Synchronisation
//!
//! We provide two `.awaitable` synchronisation primitives: [`Mutex`] provides exclusive access to a wrapped value, and [`RwLock`] provides exclusive mutable access or an arbitrary number of concurrent immutable accesses to a wrapped value (think an awaitable [`RefCell`](std::cell::RefCell)).
//!
//! ## Cells
//!
//! The [`OnceCell`] is a cell which starts empty and can be set to a value only once; calling code can `.await` the moment the cell is set to a value.
//!
//! The [`TakeCell`] is a cell which starts empty, whose contents can be set to any value any number of times, and whocse contents can only be accessed through an async `take` method which empties the cell (and which is parked when called on a presently-empty cell).

pub mod rw;
pub use rw::RwLock;

pub mod mutex;
pub use mutex::Mutex;

mod once_cell;
pub use once_cell::OnceCell;

mod take_cell;
pub use take_cell::TakeCell;

// This is safe if and only if the object pointed at by `reference` lives for at least `'longer`.
// See https://doc.rust-lang.org/nightly/std/intrinsics/fn.transmute.html for more detail.
pub(crate) unsafe fn extend_lifetime<'shorter, 'longer, T: ?Sized>(
    reference: &'shorter T,
) -> &'longer T {
    core::mem::transmute::<&'shorter T, &'longer T>(reference)
}

// This is safe if and only if the object pointed at by `reference` lives for at least `'longer`.
// See https://doc.rust-lang.org/nightly/std/intrinsics/fn.transmute.html for more detail.
pub(crate) unsafe fn extend_lifetime_mut<'shorter, 'longer, T: ?Sized>(
    reference: &'shorter mut T,
) -> &'longer mut T {
    core::mem::transmute::<&'shorter mut T, &'longer mut T>(reference)
}