fix: 修复ComfyUI SDK的cargo check和clippy警告

- 修复ComfyUIError中WebSocket变体过大的问题,使用Box包装
- 添加自定义From实现处理Box包装的WebSocket错误
- 修复所有格式化字符串警告,使用内联格式化
- 移除无用的类型转换(reqwest::Error::from)
- 修复代码质量问题:
  - 简化if语句嵌套
  - 使用?操作符替代显式错误处理
  - 优化map迭代方式
  - 使用is_some_and替代map_or

修复内容:
- 44个clippy警告全部解决
- 所有测试通过
- cargo check --lib 无错误无警告
This commit is contained in:
2025-08-08 16:12:25 +08:00
parent e874d281e0
commit e69ce2b817
9 changed files with 63 additions and 71 deletions

View File

@@ -14,7 +14,7 @@ pub enum ComfyUIError {
/// WebSocket errors
#[error("WebSocket error: {0}")]
WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
WebSocket(#[from] Box<tokio_tungstenite::tungstenite::Error>),
/// JSON serialization/deserialization errors
#[error("JSON error: {0}")]
@@ -53,6 +53,12 @@ pub enum ComfyUIError {
Io(#[from] std::io::Error),
}
impl From<tokio_tungstenite::tungstenite::Error> for ComfyUIError {
fn from(error: tokio_tungstenite::tungstenite::Error) -> Self {
Self::WebSocket(Box::new(error))
}
}
impl ComfyUIError {
/// Create a new generic error
pub fn new(message: impl Into<String>) -> Self {