代码拉取完成,页面将自动刷新
//! Defines the error type for the hypervisor.
use core::fmt;
use core::error::Error as CoreError;
use core::result::Result as CoreResult;
use alloc::boxed::Box;
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum ErrorKind {
Library,
InvalidParam,
NotFound,
AlreadyExists,
}
type DynError = dyn CoreError + Send + Sync;
#[derive(Debug)]
pub struct Error {
kind: ErrorKind,
inner: Option<Box<DynError>>,
}
pub type Result<T> = CoreResult<T, Error>;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> CoreResult<(), fmt::Error> {
fmt::Debug::fmt(self, f)
}
}
#[allow(dead_code)]
impl Error {
pub fn new(kind: ErrorKind, inner: Box<DynError>) -> Self {
Self {
kind,
inner: Some(inner),
}
}
pub fn kind(&self) -> ErrorKind {
self.kind
}
pub fn into_inner(self) -> Option<Box<DynError>> {
self.inner
}
}
impl ErrorKind {
pub fn wrap(self, inner: Box<DynError>) -> Error {
Error::new(self, inner)
}
}
impl From<ErrorKind> for Error {
fn from(kind: ErrorKind) -> Self {
Self { kind, inner: None }
}
}
impl<T> From<ErrorKind> for Result<T> {
fn from(val: ErrorKind) -> Self {
Err(val.into())
}
}
impl<T: CoreError + Send + Sync + 'static> From<T> for Error {
fn from(e: T) -> Self {
ErrorKind::Library.wrap(Box::new(e))
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。