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]
fn join(self) -> Result<Outcome<T, P>>[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]
fn as_thread_join_handle(&self) -> &JoinHandle<T>[src]
Returns a reference to the underlying JoinHandle.
fn into_thread_join_handle(self) -> JoinHandle<T>[src]
Converts into the underlying JoinHandle,
giving up panic discrimination.
Trait Implementations
impl<T, P> Debug for CheckedJoinHandle<T, P>[src]
impl<T, P> AsRef<JoinHandle<T>> for CheckedJoinHandle<T, P>[src]
fn as_ref(&self) -> &JoinHandle<T>[src]
Performs the conversion.
impl<T, P> Into<JoinHandle<T>> for CheckedJoinHandle<T, P>[src]
fn into(self) -> JoinHandle<T>[src]
Performs the conversion.