pub type Result<T> = Result<T, Box<dyn Any + Send + 'static>>;
A specialized Result type for threads.
Indicates the manner in which a thread exited.
The value contained in the Result::Err variant is the value the thread panicked with; that is, the argument the panic! macro was called with. Unlike with normal errors, this value doesn’t implement the Error trait.
Thus, a sensible way to handle a thread panic is to either:
std::panic::resume_unwind
Err variant and handle the panic in an appropriate wayA thread that completes without panicking is considered to exit successfully.
Matching on the result of a joined thread:
use std::{fs, thread, panic};
fn copy_in_thread() -> thread::Result<()> {
thread::spawn(|| {
fs::copy("foo.txt", "bar.txt").unwrap();
}).join()
}
fn main() {
match copy_in_thread() {
Ok(_) => println!("copy succeeded"),
Err(e) => panic::resume_unwind(e),
}
}pub enum Result<T> {
Ok(T),
Err(Box<dyn Any + Send>),
}
Ok(T)
Contains the success value
Err(Box<dyn Any + Send>)
Contains the error value
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/thread/type.Result.html