优化: R-PD-10 commands err_str helper 统一错误格式化(87 处)
mod.rs 加 pub fn err_str<E: ToString>,commands/ 10 文件 87 处 .map_err(|e| e.to_string()) → .map_err(err_str),残留 0(10 处复杂表达式 e 用于 format!/anyhow 保留)。行为零变化,统一入口为未来加日志/分类留点。批5,cargo workspace 0
This commit is contained in:
@@ -9,13 +9,15 @@ use tauri::State;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
use super::err_str;
|
||||
|
||||
/// 取单个 key 的值(JSON 字符串),不存在返回 None
|
||||
#[tauri::command]
|
||||
pub async fn settings_get(
|
||||
state: State<'_, AppState>,
|
||||
key: String,
|
||||
) -> Result<Option<String>, String> {
|
||||
state.settings.get(&key).await.map_err(|e| e.to_string())
|
||||
state.settings.get(&key).await.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 写 key/value(`INSERT OR REPLACE`),刷新 updated_at
|
||||
@@ -25,7 +27,7 @@ pub async fn settings_set(
|
||||
key: String,
|
||||
value: String,
|
||||
) -> Result<bool, String> {
|
||||
state.settings.set(&key, &value).await.map_err(|e| e.to_string())
|
||||
state.settings.set(&key, &value).await.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 取全部 key/value(前端启动时一次性拉回恢复偏好)
|
||||
@@ -33,7 +35,7 @@ pub async fn settings_set(
|
||||
pub async fn settings_get_all(
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<HashMap<String, String>, String> {
|
||||
let rows = state.settings.get_all().await.map_err(|e| e.to_string())?;
|
||||
let rows = state.settings.get_all().await.map_err(err_str)?;
|
||||
Ok(rows.into_iter().collect())
|
||||
}
|
||||
|
||||
@@ -43,5 +45,5 @@ pub async fn settings_delete(
|
||||
state: State<'_, AppState>,
|
||||
key: String,
|
||||
) -> Result<bool, String> {
|
||||
state.settings.delete(&key).await.map_err(|e| e.to_string())
|
||||
state.settings.delete(&key).await.map_err(err_str)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user