use std::cell::Cell;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Config {
pub stack_size: usize,
pub failure_persistence: FailurePersistence,
pub max_steps: MaxSteps,
pub max_time: Option<std::time::Duration>,
pub silence_warnings: bool,
pub record_steps_in_span: bool,
pub ungraceful_shutdown_config: UngracefulShutdownConfig,
}
std::thread_local! {
pub static UNGRACEFUL_SHUTDOWN_CONFIG: Cell<UngracefulShutdownConfig> = const { Cell::new(UngracefulShutdownConfig::new()) };
}
#[derive(Copy, Clone, Debug)]
#[non_exhaustive]
pub enum ContinuationFunctionBehavior {
Drop,
Leak,
}
impl ContinuationFunctionBehavior {
pub const fn new() -> Self {
Self::Leak
}
}
impl Default for ContinuationFunctionBehavior {
fn default() -> Self {
Self::new()
}
}
#[derive(Copy, Clone, Debug)]
#[non_exhaustive]
pub struct UngracefulShutdownConfig {
pub immediately_return_on_panic: bool,
pub continuation_function_behavior: ContinuationFunctionBehavior,
}
impl UngracefulShutdownConfig {
pub const fn new() -> Self {
Self {
immediately_return_on_panic: false,
continuation_function_behavior: ContinuationFunctionBehavior::new(),
}
}
}
impl Default for UngracefulShutdownConfig {
fn default() -> Self {
Self::new()
}
}
impl Config {
pub fn new() -> Self {
Self {
stack_size: 0xf000,
failure_persistence: FailurePersistence::Print,
max_steps: MaxSteps::FailAfter(1_000_000),
max_time: None,
silence_warnings: false,
record_steps_in_span: false,
ungraceful_shutdown_config: UngracefulShutdownConfig::default(),
}
}
}
impl Default for Config {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum FailurePersistence {
None,
Print,
File(Option<std::path::PathBuf>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum MaxSteps {
None,
FailAfter(usize),
ContinueAfter(usize),
}