From 12d6254c6b7be7db3e1b4fc5abc29cb66b9bc3a4 Mon Sep 17 00:00:00 2001 From: shenjack-5600u <3695888@qq.com> Date: Thu, 10 Apr 2025 23:36:16 +0800 Subject: [PATCH] update to edition 2024 --- ica-rs/Cargo.toml | 2 +- ica-rs/src/data_struct/ica/messages.rs | 4 ++-- ica-rs/src/data_struct/ica/messages/msg_trait.rs | 2 +- ica-rs/src/data_struct/tailchat/messages.rs | 2 +- ica-rs/src/ica.rs | 6 +++--- ica-rs/src/ica/client.rs | 8 ++++---- ica-rs/src/ica/events.rs | 6 +++--- ica-rs/src/main.rs | 4 ++-- ica-rs/src/py/call.rs | 6 +++--- ica-rs/src/py/class.rs | 5 ++--- ica-rs/src/py/class/config.rs | 5 ++--- ica-rs/src/py/class/ica.rs | 4 ++-- ica-rs/src/py/class/schdule.rs | 4 ++-- ica-rs/src/py/config.rs | 6 +++--- ica-rs/src/py/mod.rs | 11 +++++------ ica-rs/src/status.rs | 2 +- ica-rs/src/tailchat.rs | 6 +++--- ica-rs/src/tailchat/client.rs | 4 ++-- ica-rs/src/tailchat/events.rs | 6 +++--- 19 files changed, 45 insertions(+), 48 deletions(-) diff --git a/ica-rs/Cargo.toml b/ica-rs/Cargo.toml index d621410..5e56453 100644 --- a/ica-rs/Cargo.toml +++ b/ica-rs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ica-rs" version = "0.9.0" -edition = "2021" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/ica-rs/src/data_struct/ica/messages.rs b/ica-rs/src/data_struct/ica/messages.rs index 274d129..9de2f32 100644 --- a/ica-rs/src/data_struct/ica/messages.rs +++ b/ica-rs/src/data_struct/ica/messages.rs @@ -3,7 +3,7 @@ use crate::data_struct::ica::{MessageId, RoomId, UserId}; use chrono::DateTime; use serde::{Deserialize, Serialize}; -use serde_json::{json, Value as JsonValue}; +use serde_json::{Value as JsonValue, json}; use tracing::warn; pub mod msg_trait; @@ -331,7 +331,7 @@ impl SendMessage { /// file_type: 图片类型(MIME) (image/png; image/jpeg) pub fn set_img(&mut self, file: &Vec, file_type: &str, as_sticker: bool) { self.sticker = as_sticker; - use base64::{engine::general_purpose, Engine as _}; + use base64::{Engine as _, engine::general_purpose}; let base64_data = general_purpose::STANDARD.encode(file); self.file_data = Some(format!("data:{};base64,{}", file_type, base64_data)); } diff --git a/ica-rs/src/data_struct/ica/messages/msg_trait.rs b/ica-rs/src/data_struct/ica/messages/msg_trait.rs index ed2aa40..f4c9589 100644 --- a/ica-rs/src/data_struct/ica/messages/msg_trait.rs +++ b/ica-rs/src/data_struct/ica/messages/msg_trait.rs @@ -4,9 +4,9 @@ use chrono::DateTime; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; +use crate::MainStatus; use crate::data_struct::ica::messages::{At, Message, NewMessage}; use crate::data_struct::ica::{MessageId, UserId}; -use crate::MainStatus; impl Serialize for At { fn serialize(&self, serializer: S) -> Result diff --git a/ica-rs/src/data_struct/tailchat/messages.rs b/ica-rs/src/data_struct/tailchat/messages.rs index 4da1074..57b7741 100644 --- a/ica-rs/src/data_struct/tailchat/messages.rs +++ b/ica-rs/src/data_struct/tailchat/messages.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use serde::{Deserialize, Serialize}; -use serde_json::{json, Value as JsonValue}; +use serde_json::{Value as JsonValue, json}; use crate::data_struct::tailchat::{ConverseId, GroupId, MessageId, UserId}; diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index beacab3..f654464 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -5,13 +5,13 @@ pub mod events; use colored::Colorize; use rust_socketio::asynchronous::{Client, ClientBuilder}; -use rust_socketio::{async_any_callback, async_callback}; use rust_socketio::{Event, Payload, TransportType}; -use tracing::{event, span, Level}; +use rust_socketio::{async_any_callback, async_callback}; +use tracing::{Level, event, span}; use crate::config::IcaConfig; use crate::error::{ClientResult, IcaError}; -use crate::{version_str, StopGetter}; +use crate::{StopGetter, version_str}; /// icalingua 客户端的兼容版本号 pub const ICA_PROTOCOL_VERSION: &str = "2.12.28"; diff --git a/ica-rs/src/ica/client.rs b/ica-rs/src/ica/client.rs index 86df8a2..3a8774a 100644 --- a/ica-rs/src/ica/client.rs +++ b/ica-rs/src/ica/client.rs @@ -1,14 +1,14 @@ +use crate::MainStatus; use crate::data_struct::ica::messages::{DeleteMessage, SendMessage}; use crate::data_struct::ica::{RoomId, RoomIdTrait, UserId}; use crate::error::{ClientResult, IcaError}; -use crate::MainStatus; use colored::Colorize; use ed25519_dalek::{Signature, Signer, SigningKey}; -use rust_socketio::asynchronous::Client; use rust_socketio::Payload; -use serde_json::{json, Value}; -use tracing::{debug, event, span, warn, Level}; +use rust_socketio::asynchronous::Client; +use serde_json::{Value, json}; +use tracing::{Level, debug, event, span, warn}; /// "安全" 的 发送一条消息 pub async fn send_message(client: &Client, message: &SendMessage) -> bool { diff --git a/ica-rs/src/ica/events.rs b/ica-rs/src/ica/events.rs index a116118..ea3b609 100644 --- a/ica-rs/src/ica/events.rs +++ b/ica-rs/src/ica/events.rs @@ -2,14 +2,14 @@ use colored::Colorize; use rust_socketio::asynchronous::Client; use rust_socketio::{Event, Payload}; use serde_json::json; -use tracing::{event, info, span, warn, Level}; +use tracing::{Level, event, info, span, warn}; +use crate::data_struct::ica::RoomId; use crate::data_struct::ica::all_rooms::{JoinRequestRoom, Room}; use crate::data_struct::ica::messages::{Message, MessageTrait, NewMessage}; use crate::data_struct::ica::online_data::OnlineData; -use crate::data_struct::ica::RoomId; use crate::ica::client::send_message; -use crate::{client_id, help_msg, py, version_str, MainStatus, VERSION}; +use crate::{MainStatus, VERSION, client_id, help_msg, py, version_str}; /// 获取在线数据 pub async fn get_online_data(payload: Payload, _client: Client) { diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index 49e5641..c684833 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -19,7 +19,7 @@ mod tailchat; use colored::Colorize; use config::BotConfig; use error::PyPluginError; -use tracing::{event, span, Level}; +use tracing::{Level, event, span}; pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus { config: None, @@ -233,8 +233,8 @@ async fn test_macro() { use std::sync::Arc; use tokio::sync::RwLock; - use rust_socketio::asynchronous::{Client, ClientBuilder}; use rust_socketio::Payload; + use rust_socketio::asynchronous::{Client, ClientBuilder}; /// 一个简单的例子 #[derive(Clone)] diff --git a/ica-rs/src/py/call.rs b/ica-rs/src/py/call.rs index 684ccd0..273bd05 100644 --- a/ica-rs/src/py/call.rs +++ b/ica-rs/src/py/call.rs @@ -4,13 +4,13 @@ use std::sync::LazyLock; use pyo3::prelude::*; use rust_socketio::asynchronous::Client; use tokio::sync::Mutex; -use tracing::{event, info, warn, Level}; +use tracing::{Level, event, info, warn}; +use crate::MainStatus; use crate::data_struct::{ica, tailchat}; use crate::error::PyPluginError; use crate::py::consts::events_func; -use crate::py::{class, PyPlugin, PyStatus}; -use crate::MainStatus; +use crate::py::{PyPlugin, PyStatus, class}; pub struct PyTasks { pub ica_new_message: Vec>, diff --git a/ica-rs/src/py/class.rs b/ica-rs/src/py/class.rs index 62ec382..81cf579 100644 --- a/ica-rs/src/py/class.rs +++ b/ica-rs/src/py/class.rs @@ -4,12 +4,11 @@ pub mod schdule; pub mod tailchat; use pyo3::{ - pyclass, pymethods, pymodule, + Bound, IntoPyObject, PyAny, PyRef, PyResult, pyclass, pymethods, pymodule, types::{PyBool, PyModule, PyModuleMethods, PyString}, - Bound, IntoPyObject, PyAny, PyRef, PyResult, }; use toml::Value as TomlValue; -use tracing::{event, Level}; +use tracing::{Level, event}; #[derive(Clone)] #[pyclass] diff --git a/ica-rs/src/py/class/config.rs b/ica-rs/src/py/class/config.rs index b6a4b3c..8d577b7 100644 --- a/ica-rs/src/py/class/config.rs +++ b/ica-rs/src/py/class/config.rs @@ -1,14 +1,13 @@ use std::collections::HashMap; use pyo3::{ - pyclass, pymethods, + Bound, PyAny, PyResult, pyclass, pymethods, types::{ PyAnyMethods, PyBool, PyBoolMethods, PyDict, PyDictMethods, PyFloat, PyInt, PyList, PyListMethods, PyString, PyStringMethods, PyTypeMethods, }, - Bound, PyAny, PyResult, }; -use tracing::{event, Level}; +use tracing::{Level, event}; #[derive(Debug, Clone)] pub enum ConfigItem { diff --git a/ica-rs/src/py/class/ica.rs b/ica-rs/src/py/class/ica.rs index cc85ab6..f2d2d8d 100644 --- a/ica-rs/src/py/class/ica.rs +++ b/ica-rs/src/py/class/ica.rs @@ -3,15 +3,15 @@ use std::time::SystemTime; use pyo3::{pyclass, pymethods}; use rust_socketio::asynchronous::Client; use tokio::runtime::Runtime; -use tracing::{event, Level}; +use tracing::{Level, event}; +use crate::MainStatus; use crate::data_struct::ica::messages::{ DeleteMessage, MessageTrait, NewMessage, ReplyMessage, SendMessage, }; use crate::data_struct::ica::{MessageId, RoomId, RoomIdTrait, UserId}; use crate::ica::client::{delete_message, send_message, send_poke, send_room_sign_in}; use crate::py::PyStatus; -use crate::MainStatus; #[pyclass] #[pyo3(name = "IcaStatus")] diff --git a/ica-rs/src/py/class/schdule.rs b/ica-rs/src/py/class/schdule.rs index 46be576..3d8632a 100644 --- a/ica-rs/src/py/class/schdule.rs +++ b/ica-rs/src/py/class/schdule.rs @@ -1,5 +1,5 @@ -use pyo3::{pyclass, pymethods, types::PyFunction, Bound, Py, PyAny, PyTraverseError, PyVisit}; -use tracing::{event, Level}; +use pyo3::{Bound, Py, PyAny, PyTraverseError, PyVisit, pyclass, pymethods, types::PyFunction}; +use tracing::{Level, event}; #[derive(Clone, Debug)] #[pyclass] diff --git a/ica-rs/src/py/config.rs b/ica-rs/src/py/config.rs index 183f6d1..1c75e09 100644 --- a/ica-rs/src/py/config.rs +++ b/ica-rs/src/py/config.rs @@ -1,11 +1,11 @@ use std::{path::Path, str::FromStr}; use colored::Colorize; -use toml_edit::{value, DocumentMut, Key, Table, TomlError, Value}; -use tracing::{event, Level}; +use toml_edit::{DocumentMut, Key, Table, TomlError, Value, value}; +use tracing::{Level, event}; -use crate::py::PyStatus; use crate::MainStatus; +use crate::py::PyStatus; /// ```toml /// # 这个文件是由 shenbot 自动生成的, 请 **谨慎** 修改 diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index 4f1bff7..ff2a4dc 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -12,15 +12,15 @@ use std::{collections::HashMap, path::PathBuf}; use colored::Colorize; use pyo3::{ + Bound, Py, PyErr, PyResult, Python, exceptions::PyTypeError, intern, types::{PyAnyMethods, PyModule, PyTracebackMethods, PyTuple}, - Bound, Py, PyErr, PyResult, Python, }; -use tracing::{event, span, warn, Level}; +use tracing::{Level, event, span, warn}; -use crate::error::PyPluginError; use crate::MainStatus; +use crate::error::PyPluginError; use consts::config_func; @@ -36,6 +36,7 @@ pub type RawPyPlugin = (PathBuf, Option, String); #[allow(non_upper_case_globals)] static mut PyPluginStatus: OnceLock = OnceLock::new(); +#[allow(static_mut_refs)] impl PyStatus { pub fn init() { let config = @@ -394,9 +395,7 @@ impl TryFrom for PyPlugin { "加载 Python 插件 {:?} 的配置文件信息时失败:返回的不是 [str, str]", path ); - Err(PyTypeError::new_err( - "返回的不是 [str, str]".to_string(), - )) + Err(PyTypeError::new_err("返回的不是 [str, str]".to_string())) } } Err(e) => { diff --git a/ica-rs/src/status.rs b/ica-rs/src/status.rs index 9597c00..f449dc9 100644 --- a/ica-rs/src/status.rs +++ b/ica-rs/src/status.rs @@ -1,5 +1,5 @@ -use crate::config::BotConfig; use crate::MAIN_STATUS; +use crate::config::BotConfig; #[derive(Debug, Clone)] pub struct BotStatus { diff --git a/ica-rs/src/tailchat.rs b/ica-rs/src/tailchat.rs index f5fd2f9..2bd8589 100644 --- a/ica-rs/src/tailchat.rs +++ b/ica-rs/src/tailchat.rs @@ -9,13 +9,13 @@ use reqwest::ClientBuilder as reqwest_ClientBuilder; use rust_socketio::async_callback; use rust_socketio::asynchronous::{Client, ClientBuilder}; use rust_socketio::{Event, Payload, TransportType}; -use serde_json::{json, Value}; -use tracing::{event, span, Level}; +use serde_json::{Value, json}; +use tracing::{Level, event, span}; use crate::config::TailchatConfig; use crate::data_struct::tailchat::status::{BotStatus, LoginData}; use crate::error::{ClientResult, TailchatError}; -use crate::{async_any_callback_with_state, async_callback_with_state, version_str, StopGetter}; +use crate::{StopGetter, async_any_callback_with_state, async_callback_with_state, version_str}; pub async fn start_tailchat( config: TailchatConfig, diff --git a/ica-rs/src/tailchat/client.rs b/ica-rs/src/tailchat/client.rs index 8fb37de..8510e0d 100644 --- a/ica-rs/src/tailchat/client.rs +++ b/ica-rs/src/tailchat/client.rs @@ -4,8 +4,8 @@ use crate::data_struct::tailchat::messages::SendingMessage; use colored::Colorize; use reqwest::multipart; use rust_socketio::asynchronous::Client; -use serde_json::{json, Value}; -use tracing::{event, span, Level}; +use serde_json::{Value, json}; +use tracing::{Level, event, span}; pub async fn send_message(client: &Client, message: &SendingMessage) -> bool { let span = span!(Level::INFO, "tailchat send message"); diff --git a/ica-rs/src/tailchat/events.rs b/ica-rs/src/tailchat/events.rs index efa0d6d..af6ed3e 100644 --- a/ica-rs/src/tailchat/events.rs +++ b/ica-rs/src/tailchat/events.rs @@ -3,14 +3,14 @@ use std::sync::Arc; use colored::Colorize; use rust_socketio::asynchronous::Client; use rust_socketio::{Event, Payload}; -use tracing::{event, info, Level}; +use tracing::{Level, event, info}; use crate::data_struct::tailchat::messages::ReceiveMessage; use crate::data_struct::tailchat::status::{BotStatus, UpdateDMConverse}; -use crate::py::call::tailchat_new_message_py; use crate::py::PyStatus; +use crate::py::call::tailchat_new_message_py; use crate::tailchat::client::{emit_join_room, send_message}; -use crate::{client_id, help_msg, version_str, MainStatus, VERSION}; +use crate::{MainStatus, VERSION, client_id, help_msg, version_str}; /// 所有 pub async fn any_event(event: Event, payload: Payload, _client: Client, _status: Arc) {