pub struct Deloxide { /* private fields */ }Expand description
Deloxide configuration builder struct
This struct provides a fluent builder API for configuring and initializing the Deloxide deadlock detector.
§Example
use deloxide::{showcase_this, Deloxide};
// Initialize with default settings
Deloxide::new().start().expect("Failed to initialize detector");
// Initialize with logging and a custom callback
Deloxide::new()
.with_log("deadlock_logs.json")
.callback(|info| {
showcase_this().expect("Failed to launch visualization");
eprintln!("Deadlock detected! Threads: {:?}", info.thread_cycle);
})
.start()
.expect("Failed to initialize detector");Implementations§
Source§impl Deloxide
impl Deloxide
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Deloxide configuration with default settings
By default:
- Logging is disabled
- Callback is set to panic with deadlock information
- Lock order checking is disabled (only actual deadlocks detected)
Sourcepub fn with_log<P: AsRef<Path>>(self, path: P) -> Self
pub fn with_log<P: AsRef<Path>>(self, path: P) -> Self
Enable logging and set the path for the log file
This function enables logging of all mutex operations and thread events
to a file at the specified path. This log can later be visualized using
the showcase function.
§Arguments
path- Path to the log file. If the path contains “{timestamp}”, it will be replaced with the current timestamp.
§Returns
The builder for method chaining
§Example
use deloxide::Deloxide;
let config = Deloxide::new()
.with_log("logs/deadlock_{timestamp}.json");Sourcepub fn callback<F>(self, callback: F) -> Self
pub fn callback<F>(self, callback: F) -> Self
Set a custom callback to be invoked when a deadlock is detected
§Arguments
callback- Function to call when a deadlock is detected
§Returns
The builder for method chaining
§Example
use deloxide::{Deloxide, DeadlockInfo};
let config = Deloxide::new()
.callback(|info: DeadlockInfo| {
eprintln!("Deadlock detected! Thread cycle: {:?}", info.thread_cycle);
// Take remedial action, log to external system, etc.
});Sourcepub fn with_lock_order_checking(self) -> Self
pub fn with_lock_order_checking(self) -> Self
Enable lock order checking for potential deadlock detection
When enabled, the detector will check for inconsistent lock ordering patterns that could lead to deadlocks, even if no actual deadlock has occurred yet. This provides early warning of potential deadlock bugs.
Note: This may report patterns that never actually deadlock (false positives). Recommended for development and testing, not production.
§Returns
The builder for method chaining
§Example
use deloxide::Deloxide;
// Enable lock order checking for development
Deloxide::new()
.with_lock_order_checking()
.callback(|info| {
use deloxide::DeadlockSource;
match info.source {
DeadlockSource::WaitForGraph => {
println!("🚨 ACTUAL DEADLOCK! Threads are blocked.");
}
DeadlockSource::LockOrderViolation => {
println!("⚠️ SUSPECTED DEADLOCK! Dangerous lock ordering pattern.");
}
}
})
.start()
.expect("Failed to start detector");Sourcepub fn start(self) -> Result<()>
pub fn start(self) -> Result<()>
Initialize the deloxide deadlock detector with the configured settings
This finalizes the configuration and starts the deadlock detector. After calling this method, the detector will begin monitoring lock operations and can detect deadlocks.
§Returns
A Result that is Ok if initialization succeeded, or an error if it failed
§Errors
Returns an error if logger initialization fails
§Example
use deloxide::Deloxide;
Deloxide::new()
.with_log("deadlock_log.json")
.callback(|info| {
println!("Deadlock detected: {:?}", info);
})
.start()
.expect("Failed to initialize deadlock detector");