2 stable releases

2.0.0 Oct 18, 2022
1.2.2 Oct 18, 2022
1.2.1 Jun 9, 2022
1.2.0 Mar 28, 2022
0.2.1 Jun 21, 2018

#138 in Rust patterns

Download history 496594/week @ 2024-07-20 464527/week @ 2024-07-27 470057/week @ 2024-08-03 498340/week @ 2024-08-10 511015/week @ 2024-08-17 527149/week @ 2024-08-24 482354/week @ 2024-08-31 529123/week @ 2024-09-07 467105/week @ 2024-09-14 545696/week @ 2024-09-21 538021/week @ 2024-09-28 576393/week @ 2024-10-05 557111/week @ 2024-10-12 604962/week @ 2024-10-19 570183/week @ 2024-10-26 573999/week @ 2024-11-02

2,401,122 downloads per month
Used in 994 crates (16 directly)

Apache-2.0

45KB
906 lines

Fragile

Build Status Crates.io License rustc 1.42.0 Documentation

This library provides wrapper types that permit sending non Send types to other threads and use runtime checks to ensure safety.

It provides the Fragile<T>, Sticky<T> and SemiSticky<T> types which are similar in nature but have different behaviors with regards to how destructors are executed. The Fragile<T> will panic if the destructor is called in another thread, Sticky<T> will temporarily leak the object until the thread shuts down. SemiSticky<T> is a compromise of the two. It behaves like Sticky<T> but it avoids the use of thread local storage if the type does not need Drop.

Example

use std::thread;

// creating and using a fragile object in the same thread works
let val = Fragile::new(true);
assert_eq!(*val.get(), true);
assert!(val.try_get().is_ok());

// once send to another thread it stops working
thread::spawn(move || {
    assert!(val.try_get().is_err());
}).join()
    .unwrap();

Dependencies