Deloxide

Struct Deloxide 

Source
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

Source

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)
Source

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");
Source

pub fn callback<F>(self, callback: F) -> Self
where F: Fn(DeadlockInfo) + Send + Sync + 'static,

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.
    });
Source

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");
Source

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");

Trait Implementations§

Source§

impl Default for Deloxide

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,