#send #cell #non-send #failure #send-wrapper

fragile

Provides wrapper types for sending non-send values to other threads

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

#70 in Rust patterns

Download history 287254/week @ 2023-11-02 286531/week @ 2023-11-09 289033/week @ 2023-11-16 261951/week @ 2023-11-23 297461/week @ 2023-11-30 287387/week @ 2023-12-07 309583/week @ 2023-12-14 176154/week @ 2023-12-21 176241/week @ 2023-12-28 295264/week @ 2024-01-04 327757/week @ 2024-01-11 399854/week @ 2024-01-18 379196/week @ 2024-01-25 389843/week @ 2024-02-01 397874/week @ 2024-02-08 322268/week @ 2024-02-15

1,568,653 downloads per month
Used in 749 crates (13 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