transactional 0.3.1

A simple optimistic lock-free confirmation-based transactional model for Rust.
Documentation
use std::thread::{self, ThreadId};

/// A trait for ensuring thread safety of a type by checking thread ownership.
///
/// This trait provides a mechanism to verify that a particular instance is only
/// accessed from the thread that originally created it, preventing concurrent
/// access across multiple threads.
///
/// # Panics
///
/// Calls `ensure_thread_safety()` will panic if the current thread is different
/// from the thread that owns the instance.
///
/// # Examples
///
/// ```rust
/// use std::thread::{self, ThreadId};
/// use transactional::prelude::*;
///
/// struct MyType {
///     owner_thread_id: ThreadId,
/// }
/// impl ThreadSafetyChecker for MyType {
///     fn get_owner_thread_id(&self) -> ThreadId {
///         self.owner_thread_id
///     }
/// }
/// ```
///
pub trait ThreadSafetyChecker {
    fn ensure_thread_safety(&self) {
        assert!(
            thread::current().id() == self.get_owner_thread_id(),
            "Transactional state accessed from multiple threads. Concurrent access not supported. See https://github.com/jfaleiro/transactional/README.md for more information."
        );
    }
    fn get_owner_thread_id(&self) -> ThreadId;
}