| Crates.io | easy-err |
| lib.rs | easy-err |
| version | 1.0.2 |
| created_at | 2024-12-31 18:33:44.533731+00 |
| updated_at | 2025-01-22 12:36:34.469446+00 |
| description | An easy Error wrapper. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1500280 |
| size | 10,309 |
方便地将各种不同类型的错误统一为同种错误,实现了简单易用的报告功能。
It is easy to unify various types of errors into the same error, enabling easy-to-use reporting.
本文件中出现的所有英文使用微软翻译翻译,如有问题不关我事。(doge)
All English language that appears in this document is translated using Microsoft Translator, if there is no problem. (doge)
C3407087852@outlook.comBUG REPORT:
- 您的名字 (What's your name):
如果您报告的BUG被修复,您的名字将会出现在贡献名单中,可以选择匿名。
If your reported bug is fixed, your name will appear in the contributors list, optionally anonymously.
- 怎么回事 (What's the matter):
描述BUG出现的情况。
Describe the situation in which the bug occurred.
- 代码是啥 (What's the code):
引发BUG的代码,或者复现此BUG的方法。
The code that caused the bug, or the method to reproduce the bug.
Result<T, E>处理 (Handling of 'Result<T, E>')基础用法 (How to use me basically.)
use easy_err::Error;
// 自定义一个错误 (Custom an error.)
let custom_err = Error::custom("Here is a custom error.");
// 将错误写入日志文件 (Write the error into a file.)
custom_err.log_to("./log.txt");
log.txt中的输出 (Output in log.txt):
error:
time: <ErrorTime>
msg: Here is a custom error.
进阶用法 (How to use me more advanced.)
use std::fs;
use easy_err::{Error, ErrResult};
// 定义一个返回 `Result<T, easy_err::Error>` 的函数 (Define a function that returns the `Result<T, easy_err::Error>`.)
fn test() -> Result<(), Error> {
fs::File::open("An obvious mistake.")?;
Ok(())
}
// 调用 test() (Call the function.)
test().panic();
终端中的输出 (Output in Terminal):
thread 'main' panicked at F:\Projects\Rust\err\src\err.rs:196:25:
time: 2025-01-18 15:40:11.947089800 +08:00
msg: 系统找不到指定的文件。 (os error 2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\easy-err.exe` (exit code: 101)
进阶用法 (How to use me more advanced.)
use easy_err::*;
// 使用 `custom!()` 宏产生一个携带错误位置信息的自定义错误 ()
custom!("Here is a error.").report();
终端中的输出 (Output in Terminal):
error:
time: <ErrorTime>
msg: Here is a error.
where: <File>:<Line>
colored:Error::report()中使用以格式化输出。chrono:Error中使用以保存错误发生时间。Error to save the time when the error occurred.