跳到主要内容

JoinError

搜索

结构体 JoinError 

Source
pub struct JoinError { /* private fields */ }
展开描述

任务未能成功执行完成。

实现§

Source§

impl JoinError

Source

pub fn is_cancelled(&self) -> bool

如果错误是由任务被取消引起的,则返回 true。

另请参阅 模块级文档 以获取有关取消的更多信息。

Source

pub fn is_panic(&self) -> bool

如果错误是由任务 panic 引起的,则返回 true。

§示例
use std::panic;

#[tokio::main]
async fn main() {
    let err = tokio::spawn(async {
        panic!("boom");
    }).await.unwrap_err();

    assert!(err.is_panic());
}
Source

pub fn into_panic(self) -> Box<dyn Any + Send + 'static>

消费此 join error,返回任务因之 panic 的对象。

§Panics

如果 Error 并不表示底层任务因 panic 而终止,则 into_panic() 会 panic。可使用 is_panic 检查错误原因,或使用 try_into_panic 获得不会 panic 的变体。

§示例
use std::panic;

#[tokio::main]
async fn main() {
    let err = tokio::spawn(async {
        panic!("boom");
    }).await.unwrap_err();

    if err.is_panic() {
        // Resume the panic on the main task
        panic::resume_unwind(err.into_panic());
    }
}
Source

pub fn try_into_panic(self) -> Result<Box<dyn Any + Send + 'static>, JoinError>

消费此 join error。如果任务因 panic 而终止,则返回任务因之 panic 的对象;否则返回 self

§示例
use std::panic;

#[tokio::main]
async fn main() {
    let err = tokio::spawn(async {
        panic!("boom");
    }).await.unwrap_err();

    if let Ok(reason) = err.try_into_panic() {
        // Resume the panic on the main task
        panic::resume_unwind(reason);
    }
}
Source

pub fn id(&self) -> Id

返回一个相对其他当前已派生任务能标识出错任务的 task ID

Trait 实现§

Source§

impl Debug for JoinError

Source§

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

使用给定的格式化器格式化此值。 更多信息
Source§

impl Display for JoinError

Source§

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

使用给定的格式化器格式化此值。 更多信息
Source§

impl Error for JoinError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

返回此错误的更底层来源(若有)。 更多信息
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. 更多信息
Source§

impl From<JoinError> for Error

Source§

fn from(src: JoinError) -> Error

从输入类型转换为此类型。

自动 Trait 实现§

Blanket 实现§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

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

Source§

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

Mutably borrows from an owned value. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回传入的参数。

Source§

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

Source§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换的具体行为取决于 From<T> for U 的实现方式。

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 更多信息
Source§

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

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

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

执行转换。
Source§

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

Source§

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

转换出错时返回的类型。
Source§

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

执行转换。