From 2fe9a103852490e3e59effca918ae5fc4aeb2053 Mon Sep 17 00:00:00 2001 From: RocSun <710989028@qq.com> Date: Wed, 27 Dec 2023 21:54:00 +0800 Subject: [PATCH 1/4] redefine serde serialize --- src/api/fav/get_list.rs | 4 +--- src/api/ing/get_comment_list.rs | 8 +------- src/api/ing/get_list.rs | 11 +---------- src/api/news/get_list.rs | 8 +------- src/api/post/get_comment_list.rs | 3 +-- src/api/post/get_one.rs | 4 +--- src/api/user/info.rs | 11 +---------- 7 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/api/fav/get_list.rs b/src/api/fav/get_list.rs index c443f65..82f2120 100644 --- a/src/api/fav/get_list.rs +++ b/src/api/fav/get_list.rs @@ -10,14 +10,12 @@ use serde::{Deserialize, Serialize}; use std::ops::ControlFlow; #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct FavEntry { - #[serde(rename = "Title")] pub title: String, #[serde(rename = "LinkUrl")] pub url: String, - #[serde(rename = "Summary")] pub summary: String, - #[serde(rename = "Tags")] pub tags: Vec, #[serde(rename = "DateAdded")] pub create_time: String, diff --git a/src/api/ing/get_comment_list.rs b/src/api/ing/get_comment_list.rs index d925f00..59ac871 100644 --- a/src/api/ing/get_comment_list.rs +++ b/src/api/ing/get_comment_list.rs @@ -7,24 +7,18 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct IngCommentEntry { - #[serde(rename = "Id")] pub id: usize, - #[serde(rename = "Content")] pub content: String, #[serde(rename = "DateAdded")] pub create_time: String, - #[serde(rename = "StatusId")] pub status_id: usize, - #[serde(rename = "UserAlias")] pub user_alias: String, #[serde(rename = "UserDisplayName")] pub user_name: String, - #[serde(rename = "UserIconUrl")] pub user_icon_url: String, - #[serde(rename = "UserId")] pub user_id: usize, - #[serde(rename = "UserGuid")] pub user_guid: String, } diff --git a/src/api/ing/get_list.rs b/src/api/ing/get_list.rs index dd542a7..5eca27a 100644 --- a/src/api/ing/get_list.rs +++ b/src/api/ing/get_list.rs @@ -10,30 +10,21 @@ use serde::{Deserialize, Serialize}; use std::ops::ControlFlow; #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct IngEntry { - #[serde(rename = "Id")] pub id: usize, - #[serde(rename = "Content")] pub content: String, - #[serde(rename = "IsPrivate")] pub is_private: bool, - #[serde(rename = "IsLucky")] pub is_lucky: bool, - #[serde(rename = "CommentCount")] pub comment_count: usize, #[serde(rename = "DateAdded")] pub create_time: String, - #[serde(rename = "UserAlias")] pub user_alias: String, #[serde(rename = "UserDisplayName")] pub user_name: String, - #[serde(rename = "UserIconUrl")] pub user_icon_url: String, - #[serde(rename = "UserId")] pub user_id: usize, - #[serde(rename = "UserGuid")] pub user_guid: String, - #[serde(rename = "SendFrom")] pub send_from: IngSendFrom, #[serde(rename = "Icons")] pub icons: String, diff --git a/src/api/news/get_list.rs b/src/api/news/get_list.rs index 7b1bbf8..23ff0b3 100644 --- a/src/api/news/get_list.rs +++ b/src/api/news/get_list.rs @@ -8,22 +8,16 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct NewsEntry { - #[serde(rename = "Id")] pub id: usize, - #[serde(rename = "Title")] pub title: String, - #[serde(rename = "Summary")] pub summary: String, - #[serde(rename = "TopicId")] pub topic_id: usize, #[serde(rename = "TopicIcon")] pub topic_icon_url: Option, - #[serde(rename = "ViewCount")] pub view_count: usize, - #[serde(rename = "CommentCount")] pub comment_count: usize, - #[serde(rename = "DiggCount")] pub digg_count: usize, #[serde(rename = "DateAdded")] pub create_time: String, diff --git a/src/api/post/get_comment_list.rs b/src/api/post/get_comment_list.rs index ccd2f33..e14162f 100644 --- a/src/api/post/get_comment_list.rs +++ b/src/api/post/get_comment_list.rs @@ -8,8 +8,8 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] pub struct PostCommentEntry { - #[serde(rename = "Id")] pub id: usize, #[serde(rename = "Body")] pub content: String, @@ -19,7 +19,6 @@ pub struct PostCommentEntry { pub user_home_url: String, #[serde(rename = "FaceUrl")] pub avatar_url: String, - #[serde(rename = "Floor")] pub floor: usize, #[serde(rename = "DateAdded")] pub create_time: String, diff --git a/src/api/post/get_one.rs b/src/api/post/get_one.rs index 09a4e51..4fedee6 100644 --- a/src/api/post/get_one.rs +++ b/src/api/post/get_one.rs @@ -9,6 +9,7 @@ use serde_json::Value; // TODO: not elegant #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct PostEntry { pub id: usize, pub title: String, @@ -19,11 +20,8 @@ pub struct PostEntry { #[serde(rename = "dateUpdated")] pub modify_time: String, - #[serde(rename = "isDraft")] pub is_draft: bool, - #[serde(rename = "isPinned")] pub is_pinned: bool, - #[serde(rename = "isPublished")] pub is_published: bool, // WRN: diff --git a/src/api/user/info.rs b/src/api/user/info.rs index b931781..19df873 100644 --- a/src/api/user/info.rs +++ b/src/api/user/info.rs @@ -7,30 +7,21 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "PascalCase")] pub struct UserInfo { - #[serde(rename = "UserId")] pub user_id: String, #[serde(rename = "SpaceUserID")] pub space_user_id: usize, - #[serde(rename = "BlogId")] pub blog_id: usize, - #[serde(rename = "DisplayName")] pub display_name: String, - #[serde(rename = "Face")] pub face: String, - #[serde(rename = "Avatar")] pub avatar: String, - #[serde(rename = "Seniority")] pub seniority: String, - #[serde(rename = "BlogApp")] pub blog_app: String, - #[serde(rename = "FollowingCount")] pub following_count: usize, #[serde(rename = "FollowerCount")] pub followers_count: usize, - #[serde(rename = "IsVip")] pub is_vip: bool, - #[serde(rename = "Joined")] pub joined: String, } From c36338ff0b341a95e0c4ea8652a955f98e9d2efa Mon Sep 17 00:00:00 2001 From: RocSun <710989028@qq.com> Date: Wed, 27 Dec 2023 22:05:01 +0800 Subject: [PATCH 2/4] fix: the error of the parameter pass type --- src/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7b361dc..5530063 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ #![feature(try_blocks)] #![feature(if_let_guard)] #![feature(let_chains)] -#![feature(type_name_of_val)] #![feature(iterator_try_collect)] #![feature(iterator_try_reduce)] #![warn(clippy::all, clippy::nursery, clippy::cargo_common_metadata)] @@ -170,13 +169,13 @@ async fn main() -> Result<()> { } _ if let Some(create_cmd) = parser::post::create_post(&args) => { let CreateCmd { title, body, publish } = create_cmd; - let id = Post::new(pat?).create(title, body, *publish).await; + let id = Post::new(pat?).create(title.as_str(), body.as_str(), *publish).await; foe.then(|| panic_if_err(&id)); display::create_post(style, &id) } _ if let Some((id, update_cmd)) = parser::post::update_post(&args) => { let UpdateCmd { title, body, publish } = update_cmd; - let id = Post::new(pat?).update(id, title, body, publish).await; + let id = Post::new(pat?).update(id, &title, &body, &publish).await; foe.then(|| panic_if_err(&id)); display::update_post(style, &id) } From bd81a41cf7e5b93cfa6621086495976052eecdf9 Mon Sep 17 00:00:00 2001 From: RocSun <710989028@qq.com> Date: Wed, 27 Dec 2023 22:06:07 +0800 Subject: [PATCH 3/4] add toolchain --- rust-toolchain.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..fac5529 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +profile = "default" +channel = "nightly-2023-12-27" From f606b865ea2118e3bf92ebd31d54c016fc783b04 Mon Sep 17 00:00:00 2001 From: RocSun <710989028@qq.com> Date: Thu, 28 Dec 2023 13:28:01 +0800 Subject: [PATCH 4/4] Revert "fix: the error of the parameter pass type" fix: github action fialed. This reverts commit c36338ff0b341a95e0c4ea8652a955f98e9d2efa. --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5530063..7b361dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![feature(try_blocks)] #![feature(if_let_guard)] #![feature(let_chains)] +#![feature(type_name_of_val)] #![feature(iterator_try_collect)] #![feature(iterator_try_reduce)] #![warn(clippy::all, clippy::nursery, clippy::cargo_common_metadata)] @@ -169,13 +170,13 @@ async fn main() -> Result<()> { } _ if let Some(create_cmd) = parser::post::create_post(&args) => { let CreateCmd { title, body, publish } = create_cmd; - let id = Post::new(pat?).create(title.as_str(), body.as_str(), *publish).await; + let id = Post::new(pat?).create(title, body, *publish).await; foe.then(|| panic_if_err(&id)); display::create_post(style, &id) } _ if let Some((id, update_cmd)) = parser::post::update_post(&args) => { let UpdateCmd { title, body, publish } = update_cmd; - let id = Post::new(pat?).update(id, &title, &body, &publish).await; + let id = Post::new(pat?).update(id, title, body, publish).await; foe.then(|| panic_if_err(&id)); display::update_post(style, &id) }