#![no_std]
#![forbid(unsafe_code)]
#![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
mod sync;
#[cfg(feature = "alloc")]
mod async_scope;
pub mod fixed;
pub use sync::{defer, guard, Always, DeferGuard, ScopeGuard, Strategy};
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub use sync::{
defer_on_success, defer_on_unwind, guard_on_success, guard_on_unwind, OnSuccess, OnUnwind,
};
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub use async_scope::{AsyncScope, LocalAsyncScope, LocalRun, SendAsyncScope, SendRun};
#[macro_export]
macro_rules! defer {
(move $($body:tt)*) => {
let _defer_guard = $crate::defer(move || {
$($body)*
});
};
($($body:tt)*) => {
let _defer_guard = $crate::defer(|| {
$($body)*
});
};
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[macro_export]
macro_rules! async_scope {
($scope:ident, $body:block) => {
async {
let mut $scope = $crate::LocalAsyncScope::new();
let __async_safe_defer_result = (async $body).await;
$scope.finish().await;
__async_safe_defer_result
}
};
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[macro_export]
macro_rules! send_async_scope {
($scope:ident, $body:block) => {
async {
let mut $scope = $crate::SendAsyncScope::new();
let __async_safe_defer_result = (async $body).await;
$scope.finish().await;
__async_safe_defer_result
}
};
}