feat: 添加一些实用的扩展方法

This commit is contained in:
lanyeeee
2025-07-10 05:52:04 +08:00
parent acd7b2902e
commit 1235ce1657
4 changed files with 24 additions and 0 deletions
+1
View File
@@ -267,6 +267,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
name = "bilibili-video-downloader"
version = "0.1.0"
dependencies = [
"anyhow",
"serde",
"serde_json",
"specta",
+2
View File
@@ -27,6 +27,8 @@ specta = { version = "=2.0.0-rc.20", features = ["serde_json"] }
tauri-specta = { version = "=2.0.0-rc.20", features = ["derive", "typescript"] }
specta-typescript = { version = "=0.0.7" }
anyhow = { version = "1.0.98" }
[profile.release]
strip = true
lto = true
+20
View File
@@ -0,0 +1,20 @@
pub trait AnyhowErrorToStringChain {
/// 将 `anyhow::Error` 转换为chain格式
/// # Example
/// 0: error message\
/// 1: error message\
/// 2: error message
fn to_string_chain(&self) -> String;
}
impl AnyhowErrorToStringChain for anyhow::Error {
fn to_string_chain(&self) -> String {
use std::fmt::Write;
self.chain()
.enumerate()
.fold(String::new(), |mut output, (i, e)| {
let _ = writeln!(output, "{i}: {e}");
output
})
}
}
+1
View File
@@ -1,4 +1,5 @@
mod commands;
mod extensions;
mod utils;
use tauri::Wry;