Skip to content

Stable 1.0.0

Choose a tag to compare

@AsfhtgkDavid AsfhtgkDavid released this 21 Feb 12:09
· 22 commits to main since this release
0196821

I am excited to announce the first stable release of struct-threads! 🦀

struct-threads is a lightweight Rust library designed to provide a clean, object-oriented approach to structuring thread logic. By encapsulating thread state within structs that implement the Runnable trait, this library helps you write more readable, maintainable, and testable concurrent code.

✨ Features in this release

  • The Runnable Trait: Define your task logic and its precise return type (Output) clearly and safely.
  • The Thread Extension Trait: Automatically gain a convenient .start() method for any Runnable struct.
  • Zero-Cost Abstraction: Under the hood, it acts as a direct, zero-overhead wrapper around std::thread::spawn.
  • Type-Safe Returns: Seamlessly join the thread and retrieve the exact type specified in your task's Output.

🚀 Quick Start

// Add to your project: cargo add struct-threads

use struct_threads::{Runnable, Thread};

struct MyTask { data: i32 }

impl Runnable for MyTask {
    type Output = i32;
    fn run(self) -> Self::Output {
        self.data * 2
    }
}

let handle = MyTask { data: 21 }.start();
assert_eq!(handle.join().unwrap(), 42);

Feedback, bug reports, and pull requests are highly appreciated! If you find this library useful, consider giving it a ⭐.