Struct panic_control::CheckedJoinHandle [] [src]

pub struct CheckedJoinHandle<T, P> { /* fields omitted */ }

Wraps std::thread::JoinHandle for panic value discrimination.

A CheckedJoinHandle works like a standard JoinHandle, except that its join() method dynamically checks the type of the possible panic value for matching the type that is the parameter of the Context this handle was obtained from, and if the type matches, returns the resolved value in the "successful panic" result variant.

See the documentation of the join() method for details and an example of use.

Methods

impl<T, P: Any> CheckedJoinHandle<T, P>
[src]

[src]

Works like std::thread::JoinHandle::join(), except that when the child thread's panic value is of the expected type, it is returned in Ok(Outcome::Panicked(_)). If the child thread's closure returns normally, its return value is returned in Ok(Outcome::NoPanic(_))

Examples

use panic_control::{Context, Outcome};
use std::thread;

#[derive(Debug, PartialEq, Eq)]
struct Expected(pub u32);

let ctx = Context::<Expected>::new();
let h = ctx.spawn(|| {
    panic!(Expected(42));
});

let outcome = h.join().unwrap();

match outcome {
    Outcome::Panicked(Expected(n)) => {
        println!("thread panicked as expected with {}", n);
    }
    _ => panic!("unexpected return value from join()")
}

impl<T, P> CheckedJoinHandle<T, P>
[src]

[src]

Returns a reference to the underlying JoinHandle.

[src]

Converts into the underlying JoinHandle, giving up panic discrimination.

Trait Implementations

impl<T, P> Debug for CheckedJoinHandle<T, P>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T, P> AsRef<JoinHandle<T>> for CheckedJoinHandle<T, P>
[src]

[src]

Performs the conversion.

impl<T, P> Into<JoinHandle<T>> for CheckedJoinHandle<T, P>
[src]

[src]

Performs the conversion.

Auto Trait Implementations

impl<T, P> Send for CheckedJoinHandle<T, P> where
    P: Send,
    T: Send

impl<T, P> Sync for CheckedJoinHandle<T, P> where
    P: Sync,
    T: Sync