pub struct GaiaError { /* private fields */ }Expand description
Gaia 错误类型,包装了具体的错误类 GaiaErrorKind
这里使用 Box 来减少枚举的大小,提高性能
Implementations§
Source§impl GaiaError
impl GaiaError
Sourcepub fn syntax_error(message: impl ToString, location: SourceLocation) -> Self
pub fn syntax_error(message: impl ToString, location: SourceLocation) -> Self
Sourcepub fn io_error(io_error: Error, url: Url) -> Self
pub fn io_error(io_error: Error, url: Url) -> Self
创建一个IO错误
当文件读写、网络请求等IO操作失败时使用此函数创建错误
§参数
io_error- 底层的IO错误url- 与IO操作相关的URL(如文件路径或网络地址)
§返回值
返回一个包含IO错误信息的GaiaError实例
§示例
use gaia_types::GaiaError;
use url::Url;
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "文件不存在");
let url = Url::from_file_path("/path/to/file")
.ok()
.and_then(|x| Some(x))
.unwrap_or_else(|| Url::parse("file:///path/to/file").unwrap());
let error = GaiaError::io_error(io_err, url);Sourcepub fn invalid_instruction(
instruction: impl ToString,
architecture: Architecture,
) -> Self
pub fn invalid_instruction( instruction: impl ToString, architecture: Architecture, ) -> Self
Sourcepub fn unsupported_architecture(architecture: Architecture) -> Self
pub fn unsupported_architecture(architecture: Architecture) -> Self
Sourcepub fn invalid_range(length: usize, expect: usize) -> Self
pub fn invalid_range(length: usize, expect: usize) -> Self
Sourcepub fn invalid_data(data: impl ToString) -> Self
pub fn invalid_data(data: impl ToString) -> Self
Sourcepub fn kind(&self) -> &GaiaErrorKind
pub fn kind(&self) -> &GaiaErrorKind
返回错误的种类。
Sourcepub fn not_implemented(feature: impl ToString) -> Self
pub fn not_implemented(feature: impl ToString) -> Self
Sourcepub fn adapter_error(
adapter_name: impl ToString,
message: impl ToString,
source: Option<Box<GaiaError>>,
) -> Self
pub fn adapter_error( adapter_name: impl ToString, message: impl ToString, source: Option<Box<GaiaError>>, ) -> Self
Sourcepub fn platform_unsupported(
platform: impl ToString,
operation: impl ToString,
) -> Self
pub fn platform_unsupported( platform: impl ToString, operation: impl ToString, ) -> Self
Sourcepub fn config_error(
config_path: Option<impl ToString>,
message: impl ToString,
) -> Self
pub fn config_error( config_path: Option<impl ToString>, message: impl ToString, ) -> Self
Sourcepub fn unsupported_target(target: CompilationTarget) -> Self
pub fn unsupported_target(target: CompilationTarget) -> Self
Sourcepub fn compilation_failed(
target: CompilationTarget,
message: impl ToString,
) -> Self
pub fn compilation_failed( target: CompilationTarget, message: impl ToString, ) -> Self
Sourcepub fn save_error(format: impl ToString, message: impl ToString) -> Self
pub fn save_error(format: impl ToString, message: impl ToString) -> Self
Sourcepub fn unsupported_feature(
feature: impl ToString,
location: SourceLocation,
) -> Self
pub fn unsupported_feature( feature: impl ToString, location: SourceLocation, ) -> Self
Sourcepub fn custom_error(message: impl ToString) -> GaiaError
pub fn custom_error(message: impl ToString) -> GaiaError
Sourcepub fn unreachable() -> Self
pub fn unreachable() -> Self
Trait Implementations§
Source§impl Error for GaiaError
为GaiaError实现标准库Error trait
impl Error for GaiaError
为GaiaError实现标准库Error trait
这使得GaiaError可以作为标准错误类型使用
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<GaiaErrorKind> for GaiaError
将GaiaErrorKind转换为GaiaError的实现
impl From<GaiaErrorKind> for GaiaError
将GaiaErrorKind转换为GaiaError的实现
这个转换会自动将错误种类包装到Box中, 这是GaiaError结构体所要求的,可以减少内存占用
Source§fn from(error: GaiaErrorKind) -> Self
fn from(error: GaiaErrorKind) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for GaiaError
impl !RefUnwindSafe for GaiaError
impl Send for GaiaError
impl Sync for GaiaError
impl Unpin for GaiaError
impl !UnwindSafe for GaiaError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more