From ab1cfc7dbdb20974d6eb8be7ed52edd6d096b75d Mon Sep 17 00:00:00 2001 From: Millione Date: Wed, 9 Aug 2023 16:46:19 +0800 Subject: [PATCH] fix: trailing whitespace --- Cargo.lock | 4 +- pilota-build/Cargo.toml | 2 +- pilota-build/src/codegen/mod.rs | 8 +- pilota-build/src/codegen/thrift/mod.rs | 4 +- pilota-build/src/codegen/workspace.rs | 2 + pilota-build/src/plugin/mod.rs | 2 +- pilota-build/src/test/mod.rs | 1 + pilota-build/test_data/unknown_fields.rs | 239 ++++++++++++++++++++--- pilota/Cargo.toml | 2 +- pilota/src/thrift/unknown.rs | 5 +- 10 files changed, 229 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5389d5c..448ff54a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -715,7 +715,7 @@ dependencies = [ [[package]] name = "pilota" -version = "0.8.0" +version = "0.8.1" dependencies = [ "anyhow", "async-recursion", @@ -738,7 +738,7 @@ dependencies = [ [[package]] name = "pilota-build" -version = "0.8.1" +version = "0.8.2" dependencies = [ "anyhow", "async-trait", diff --git a/pilota-build/Cargo.toml b/pilota-build/Cargo.toml index 69643ead..92dd106b 100644 --- a/pilota-build/Cargo.toml +++ b/pilota-build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pilota-build" -version = "0.8.1" +version = "0.8.2" edition = "2021" description = "Compile thrift and protobuf idl into rust code at compile-time." documentation = "https://docs.rs/pilota-build" diff --git a/pilota-build/src/codegen/mod.rs b/pilota-build/src/codegen/mod.rs index c047c5c2..e7b1e898 100644 --- a/pilota-build/src/codegen/mod.rs +++ b/pilota-build/src/codegen/mod.rs @@ -11,7 +11,7 @@ use itertools::Itertools; use normpath::PathExt; use pkg_tree::PkgNode; use quote::quote; -use rayon::prelude::IntoParallelRefIterator; +use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use traits::CodegenBackend; use self::workspace::Workspace; @@ -429,8 +429,6 @@ where where B: Send, { - use rayon::iter::ParallelIterator; - let mods = items.into_group_map_by(|CodegenItem { def_id, .. }| { let path = Arc::from_iter(self.mod_path(*def_id).iter().map(|s| s.0.clone())); tracing::debug!("ths path of {:?} is {:?}", def_id, path); @@ -504,9 +502,9 @@ where #![allow(warnings, clippy::all)] {stream} }}"#}; - + let stream = stream.lines().map(|s| s.trim_end()).join("\n"); let mut file = std::io::BufWriter::new(std::fs::File::create(&file_name).unwrap()); - file.write_all(stream.to_string().as_bytes()).unwrap(); + file.write_all(stream.as_bytes()).unwrap(); file.flush().unwrap(); fmt_file(file_name) } diff --git a/pilota-build/src/codegen/thrift/mod.rs b/pilota-build/src/codegen/thrift/mod.rs index a203bdf0..5f6cea84 100644 --- a/pilota-build/src/codegen/thrift/mod.rs +++ b/pilota-build/src/codegen/thrift/mod.rs @@ -398,7 +398,7 @@ impl ThriftBackend { {record_ptr} let field_ident = {read_field_begin}; if field_ident.field_type == ::pilota::thrift::TType::Stop {{ - {field_stop_len} + {field_stop_len} break; }} else {{ {field_begin_len} @@ -685,7 +685,7 @@ impl CodegenBackend for ThriftBackend { {record_ptr} let field_ident = {read_field_begin}; if field_ident.field_type == ::pilota::thrift::TType::Stop {{ - {field_stop_len} + {field_stop_len} break; }} else {{ {field_begin_len} diff --git a/pilota-build/src/codegen/workspace.rs b/pilota-build/src/codegen/workspace.rs index fe197733..59d6c84f 100644 --- a/pilota-build/src/codegen/workspace.rs +++ b/pilota-build/src/codegen/workspace.rs @@ -287,6 +287,8 @@ where stream.push_str(&format!("pub use {}::*;", main_mod_path.join("::"))); } + let stream = stream.lines().map(|s| s.trim_end()).join("\n"); + let src_file = base_dir.as_ref().join(&*info.name).join("src/lib.rs"); std::fs::write(&src_file, stream)?; diff --git a/pilota-build/src/plugin/mod.rs b/pilota-build/src/plugin/mod.rs index ff511432..6e31a49f 100644 --- a/pilota-build/src/plugin/mod.rs +++ b/pilota-build/src/plugin/mod.rs @@ -347,7 +347,7 @@ impl Plugin for ImplDefaultPlugin { if !fields.is_empty() { fields.push_str(",\n"); } - fields.push_str("unknown_fields: ::pilota::Bytes::new()"); + fields.push_str("_unknown_fields: ::pilota::LinkedBytes::new()"); } cx.with_adjust_mut(def_id, |adj| { diff --git a/pilota-build/src/test/mod.rs b/pilota-build/src/test/mod.rs index 01861031..3d6b5936 100644 --- a/pilota-build/src/test/mod.rs +++ b/pilota-build/src/test/mod.rs @@ -188,6 +188,7 @@ fn test_unknown_fields() { crate::Builder::thrift() .ignore_unused(false) .keep_unknown_fields([source.into()]) + .plugin(SerdePlugin) .compile_with_config( vec![IdlService::from_path(source.to_path_buf())], crate::Output::File(target.into()), diff --git a/pilota-build/test_data/unknown_fields.rs b/pilota-build/test_data/unknown_fields.rs index 9f95b69c..5b21337a 100644 --- a/pilota-build/test_data/unknown_fields.rs +++ b/pilota-build/test_data/unknown_fields.rs @@ -2,7 +2,18 @@ pub mod unknown_fields { #![allow(warnings, clippy::all)] pub mod must_gen_items { - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct A { pub a: ::std::option::Option, pub _unknown_fields: ::pilota::LinkedBytes, @@ -153,7 +164,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct B { pub a: ::std::option::Option, pub _unknown_fields: ::pilota::LinkedBytes, @@ -311,7 +333,18 @@ pub mod unknown_fields { } pub mod unknown_fields { - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct A { pub bytes: ::pilota::Bytes, @@ -516,7 +549,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct D { pub td: Td, pub _unknown_fields: ::pilota::LinkedBytes, @@ -685,7 +729,18 @@ pub mod unknown_fields { } #[::async_trait::async_trait] pub trait Test {} - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct TestTest123ArgsSend {} #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsSend { @@ -812,7 +867,18 @@ pub mod unknown_fields { } } pub const TEST_LIST: [&'static str; 2] = ["hello", "world"]; - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct B { pub faststr: ::pilota::FastStr, @@ -1111,7 +1177,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct SubMessage { pub _unknown_fields: ::pilota::LinkedBytes, } @@ -1245,7 +1322,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct StException { pub message: ::std::option::Option<::pilota::FastStr>, pub _unknown_fields: ::pilota::LinkedBytes, @@ -1406,7 +1494,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct TestTest123ArgsRecv {} #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsRecv { @@ -1539,7 +1638,18 @@ pub mod unknown_fields { map }; } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct C { pub a: super::must_gen_items::A, pub _unknown_fields: ::pilota::LinkedBytes, @@ -1707,7 +1817,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct Message { pub _unknown_fields: ::pilota::LinkedBytes, } @@ -1842,7 +1963,7 @@ pub mod unknown_fields { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] pub enum TestUnion { #[derivative(Default)] @@ -2027,7 +2148,7 @@ pub mod unknown_fields { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] pub enum TestTestExceptionException { #[derivative(Default)] @@ -2157,7 +2278,7 @@ pub mod unknown_fields { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] pub enum TestTestExceptionResultRecv { #[derivative(Default)] @@ -2320,7 +2441,7 @@ pub mod unknown_fields { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] pub enum TestTest123ResultRecv { #[derivative(Default)] @@ -2438,7 +2559,7 @@ pub mod unknown_fields { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] #[repr(i32)] #[derive(Copy)] pub enum Index { @@ -2492,7 +2613,18 @@ pub mod unknown_fields { protocol.i32_len(*self as i32) } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct ObjReq { pub _unknown_fields: ::pilota::LinkedBytes, } @@ -2632,7 +2764,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct TestTestExceptionArgsSend { pub req: ObjReq, } @@ -2796,7 +2939,7 @@ pub mod unknown_fields { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] pub enum TestTest123ResultSend { #[derivative(Default)] @@ -2889,7 +3032,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct Td(pub ::std::vec::Vec<::std::vec::Vec<::pilota::FastStr>>); impl ::std::ops::Deref for Td { @@ -2994,7 +3148,18 @@ pub mod unknown_fields { }) } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct TestTestExceptionArgsRecv { pub req: ObjReq, } @@ -3158,7 +3323,7 @@ pub mod unknown_fields { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] pub enum TestTestExceptionResultSend { #[derivative(Default)] @@ -3334,7 +3499,7 @@ pub mod unknown_fields { pub trait Test {} #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] pub enum TestTest123ResultRecv { #[derivative(Default)] @@ -3429,7 +3594,7 @@ pub mod unknown_fields { } #[derive(PartialOrd, Hash, Eq, Ord, Debug, ::pilota::derivative::Derivative)] #[derivative(Default)] - #[derive(Clone, PartialEq)] + #[derive(::pilota::serde::Serialize, ::pilota::serde::Deserialize, Clone, PartialEq)] pub enum TestTest123ResultSend { #[derivative(Default)] @@ -3522,7 +3687,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct TestTest123ArgsSend {} #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsSend { @@ -3648,7 +3824,18 @@ pub mod unknown_fields { + protocol.struct_end_len() } } - #[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)] + #[derive( + PartialOrd, + Hash, + Eq, + Ord, + Debug, + Default, + ::pilota::serde::Serialize, + ::pilota::serde::Deserialize, + Clone, + PartialEq, + )] pub struct TestTest123ArgsRecv {} #[::async_trait::async_trait] impl ::pilota::thrift::Message for TestTest123ArgsRecv { diff --git a/pilota/Cargo.toml b/pilota/Cargo.toml index 62911f04..7382d0f2 100644 --- a/pilota/Cargo.toml +++ b/pilota/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pilota" -version = "0.8.0" +version = "0.8.1" edition = "2021" description = "Pilota is a thrift and protobuf implementation in pure rust with high performance and extensibility." documentation = "https://docs.rs/pilota" diff --git a/pilota/src/thrift/unknown.rs b/pilota/src/thrift/unknown.rs index 66146382..536cb9cf 100644 --- a/pilota/src/thrift/unknown.rs +++ b/pilota/src/thrift/unknown.rs @@ -4,8 +4,9 @@ use bytes::Bytes; const DEFAULT_DEQUE_SIZE: usize = 16; -#[derive(PartialOrd, Hash, Eq, Ord, Debug, Clone, PartialEq)] - +#[derive( + PartialOrd, Hash, Eq, Ord, Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, +)] pub struct LinkedBytes { pub list: VecDeque, pub size: usize,