Introduce pinned_async macro

This commit is contained in:
Reinout Meliesie 2025-02-18 18:31:05 +01:00
parent 90594514bd
commit a3040e6735
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
2 changed files with 16 additions and 3 deletions

View file

@ -48,9 +48,10 @@ fn show_window ( application : & Application ) {
let ui = UI :: new (
window ,
|film_uuid| Box :: pin ( async {
data_manager . get_film_details (film_uuid) . await . unwrap ()
} ) ,
|film_uuid| pinned_async ! {
data_manager . get_film_details (film_uuid) . await
. expect ("A film with the given UUID should exist")
} ,
) ;
window . show () ;

View file

@ -5,3 +5,15 @@ pub fn leak < 'l , Type > ( inner : Type ) -> & 'l Type {
pub fn leak_mut < 'l , Type > ( inner : Type ) -> & 'l mut Type {
Box :: leak ( Box :: new (inner) )
}
macro_rules ! pinned_async { (
$ ( $ async_expression : expr ) ; +
) => {
Box :: pin ( async {
$ ( $ async_expression ) ; +
} )
} }
pub (crate) use pinned_async ;