W3cubDocs

/Rust

Type Definition std::thread::Result

type Result<T> = Result<T, Box<Any + Send + 'static>>;

A specialized Result type for threads.

Indicates the manner in which a thread exited.

A thread that completes without panicking is considered to exit successfully.

Examples

use std::thread;
use std::fs;

fn copy_in_thread() -> thread::Result<()> {
    thread::spawn(move || { fs::copy("foo.txt", "bar.txt").unwrap(); }).join()
}

fn main() {
    match copy_in_thread() {
        Ok(_) => println!("this is fine"),
        Err(_) => println!("thread panicked"),
    }
}

© 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