Struct CheckedJoinHandle

Source
pub struct CheckedJoinHandle<T, P> { /* private fields */ }
Expand description

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.

Implementations§

Source§

impl<T, P: Any> CheckedJoinHandle<T, P>

Source

pub fn join(self) -> Result<Outcome<T, P>>

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()")
}
Source§

impl<T, P> CheckedJoinHandle<T, P>

Source

pub fn as_thread_join_handle(&self) -> &JoinHandle<T>

Returns a reference to the underlying JoinHandle.

Source

pub fn into_thread_join_handle(self) -> JoinHandle<T>

Converts into the underlying JoinHandle, giving up panic discrimination.

Trait Implementations§

Source§

impl<T, P> AsRef<JoinHandle<T>> for CheckedJoinHandle<T, P>

Source§

fn as_ref(&self) -> &JoinHandle<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, P> Debug for CheckedJoinHandle<T, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, P> Into<JoinHandle<T>> for CheckedJoinHandle<T, P>

Source§

fn into(self) -> JoinHandle<T>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl<T, P> Freeze for CheckedJoinHandle<T, P>

§

impl<T, P> !RefUnwindSafe for CheckedJoinHandle<T, P>

§

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

§

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

§

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

§

impl<T, P> !UnwindSafe for CheckedJoinHandle<T, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.