macro_rules! create_token {
(
$(#[$struct_meta:meta])*
$v:vis struct $token_name:ident<'ui>;
pop $pop:expr;
$(#[$end_meta:meta])*
drop { $on_drop:expr }
) => {
#[must_use]
$(#[$struct_meta])*
#[doc = "\n# Drop order\n\nTokens sharing this native resource stack must finish in reverse creation order. Window- or table-local tokens must also finish in their originating scope. Prefer the corresponding closure helper when available. Invalid use panics before FFI, with cleanup deferred when the original scope can be restored safely."]
pub struct $token_name<'a> {
scope: $crate::scope::NativeScopeToken<'a>,
_phantom: std::marker::PhantomData<&'a $crate::Ui>,
}
impl<'a> $token_name<'a> {
pub(crate) fn new(ui: &'a $crate::Ui) -> Self {
Self {
scope: ui.begin_native_scope($pop, stringify!($token_name)),
_phantom: std::marker::PhantomData,
}
}
$(#[$end_meta])*
#[doc = "\n# Panics\n\nPanics before FFI if a later token on the same native resource stack is active or this token is no longer in its originating native scope."]
#[inline]
pub fn end(self) {
}
}
impl Drop for $token_name<'_> {
fn drop(&mut self) {
self.scope.finish_with(|| {
$on_drop
});
}
}
}
}