macro_rules! ghost {
( $($_:tt)* ) => { ... };
(
$( #[tag($meta:meta)] )?
$( #[no_init] )?
$( |$ghost_ctx:pat| )?
$expr_or_block:expr
) => { ... };
}
Expand description
Ghost
expressions. PhantomCode
of sorts, if you want.
See the main docs for more info.
Examples
?
and .await
work inside it.
use ::ghosts::vestibule::*;
fn main ()
-> ::std::io::Result<()>
{
let casper = ghost!({
let foo = ::std::fs::File::open("/the/door")?;
});
async {
let in_the_shell = ghost!({
let bar = example().await;
});
};
Ok(())
}
async
fn example ()
{
// …
}
break
and continue
work inside it, provided they be labelled.
use ::ghosts::vestibule::*;
let _: i32 = 'labelled: loop {
let casper = ghost!({
break 'labelled 42;
});
break 0;
};
ghost!
expressions consume ownership of their captures…
ⓘ
use ::ghosts::vestibule::*;
let owned = String::from("…");
let casper = ghost!(owned);
drop(owned); // Error, use of moved value
- (note: once in the Ghost Realm™, things stay there. There is no way for ownership relinquished over the Ghost Realm™ to ever be claimed back outside of it)
… unless the #[no_init]
opt-out is used
use ::ghosts::vestibule::*;
let owned = String::from("…");
let casper = ghost!(#[no_init] {
owned
});
drop(owned); // Ok