From 021f9efed3623c14ebde17d1253e6af44bb14a07 Mon Sep 17 00:00:00 2001 From: Geoffry Song Date: Mon, 12 Feb 2024 02:06:16 -0800 Subject: [PATCH] Organize imports with rustfmt --- .rustfmt.toml | 3 +++ examples/src/zero_copy/main.rs | 3 ++- pb-jelly-gen/src/codegen.rs | 6 ++---- pb-jelly-gen/src/lib.rs | 29 +++++++++++++-------------- pb-jelly/src/tests/mod.rs | 7 ++++--- pb-jelly/src/varint.rs | 6 ++++-- pb-test/pb_test_gen/src/main.rs | 3 +-- pb-test/src/bench.rs | 16 +++++++-------- pb-test/src/pbtest.rs | 12 +++++++---- pb-test/src/verify_generated_files.rs | 6 ++++-- 10 files changed, 50 insertions(+), 41 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index 4e6a033..757f198 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -22,3 +22,6 @@ match_block_trailing_comma = true # We prefer it already so just do it here use_try_shorthand = true use_field_init_shorthand = true + +imports_granularity = "Module" +group_imports = "StdExternalCrate" diff --git a/examples/src/zero_copy/main.rs b/examples/src/zero_copy/main.rs index 4e5cca3..4aa356a 100644 --- a/examples/src/zero_copy/main.rs +++ b/examples/src/zero_copy/main.rs @@ -1,10 +1,11 @@ +use std::io::Cursor; + use bytes::Bytes; use pb_jelly::{ Lazy, Message, }; use proto_zero_copy::basic::BytesMessage; -use std::io::Cursor; fn main() -> std::io::Result<()> { // Create 1kb of Data diff --git a/pb-jelly-gen/src/codegen.rs b/pb-jelly-gen/src/codegen.rs index 04e02f5..b28a68b 100644 --- a/pb-jelly-gen/src/codegen.rs +++ b/pb-jelly-gen/src/codegen.rs @@ -15,10 +15,8 @@ use indexmap::{ IndexSet, }; use lazy_static::lazy_static; -use pb_jelly::{ - extensions::Extensible, - Message, -}; +use pb_jelly::extensions::Extensible; +use pb_jelly::Message; use regex::Regex; use crate::protos::google::protobuf::compiler::plugin; diff --git a/pb-jelly-gen/src/lib.rs b/pb-jelly-gen/src/lib.rs index 2414f9e..7d18464 100644 --- a/pb-jelly-gen/src/lib.rs +++ b/pb-jelly-gen/src/lib.rs @@ -31,28 +31,27 @@ //! } //! ``` -use crate::protos::google::protobuf::{ - compiler::plugin::CodeGeneratorRequest, - descriptor::FileDescriptorSet, +use std::convert::AsRef; +use std::error::Error; +use std::fs; +use std::iter::IntoIterator; +use std::path::{ + self, + Path, + PathBuf, }; +use std::process::Command; + use pb_jelly::Message; -use std::{ - convert::AsRef, - error::Error, - fs, - iter::IntoIterator, - path::{ - self, - Path, - PathBuf, - }, - process::Command, -}; use walkdir::WalkDir; +use crate::protos::google::protobuf::compiler::plugin::CodeGeneratorRequest; +use crate::protos::google::protobuf::descriptor::FileDescriptorSet; + pub mod codegen; /// Don't depend on this module, it's only public so that `protoc-gen-jellyrust` can use it #[doc(hidden)] +#[rustfmt::skip] pub mod protos; /// A "no frills" way to generate Rust bindings for your proto files. `src_paths` is a list of diff --git a/pb-jelly/src/tests/mod.rs b/pb-jelly/src/tests/mod.rs index 04926e3..4b7b7e3 100644 --- a/pb-jelly/src/tests/mod.rs +++ b/pb-jelly/src/tests/mod.rs @@ -12,9 +12,6 @@ use bytes::{ BufMut, }; -use crate::varint; -use crate::wire_format; - use super::{ ensure_split, ensure_wire_format, @@ -26,6 +23,10 @@ use super::{ PbBufferReader, PbBufferWriter, }; +use crate::{ + varint, + wire_format, +}; /// A wrapper around a `Vec` which owns its contents. #[derive(Clone, PartialEq, Debug, Default)] diff --git a/pb-jelly/src/varint.rs b/pb-jelly/src/varint.rs index 5d63e0c..18fabe5 100644 --- a/pb-jelly/src/varint.rs +++ b/pb-jelly/src/varint.rs @@ -1,10 +1,11 @@ -use bytes::Buf; use std::cmp::min; use std::io::{ self, Write, }; +use bytes::Buf; + #[inline] pub const fn serialized_length(mut val: u64) -> usize { let mut ans = 1; @@ -93,9 +94,10 @@ pub fn ensure_read(buf: &mut B) -> io::Result { #[test] fn test_basic() { - use crate::Message; use std::io::Cursor; + use crate::Message; + let from_vec = |vec| read(&mut Cursor::new(vec)).unwrap().unwrap(); let from_vec_split = |mut first_vec: Vec| { diff --git a/pb-test/pb_test_gen/src/main.rs b/pb-test/pb_test_gen/src/main.rs index bd77a4c..67886d6 100644 --- a/pb-test/pb_test_gen/src/main.rs +++ b/pb-test/pb_test_gen/src/main.rs @@ -1,12 +1,11 @@ -use pb_jelly_gen::GenProtos; use std::{ env, fs, }; +use pb_jelly_gen::GenProtos; #[cfg(feature = "bench_prost")] use prost_build; - #[cfg(feature = "bench_rust_protobuf")] use protoc_rust::Customize; diff --git a/pb-test/src/bench.rs b/pb-test/src/bench.rs index f60dbcf..ac91730 100644 --- a/pb-test/src/bench.rs +++ b/pb-test/src/bench.rs @@ -1,5 +1,8 @@ #[cfg(test)] mod benches { + use std::hint::black_box; + use std::io::Cursor; + use bytes::Bytes; use compact_str::CompactString; use pb_jelly::{ @@ -17,10 +20,6 @@ mod benches { VecData, }; use serde::Deserialize; - use std::{ - hint::black_box, - io::Cursor, - }; use test::Bencher; #[bench] @@ -279,10 +278,6 @@ mod prost { #[cfg(all(test, feature = "bench_rust_protobuf"))] mod rust_protobuf { - use crate::gen::rust_protobuf::bench::{ - BytesData, - StringMessage, - }; use bytes::Bytes; use protobuf::{ CodedInputStream, @@ -290,6 +285,11 @@ mod rust_protobuf { }; use test::Bencher; + use crate::gen::rust_protobuf::bench::{ + BytesData, + StringMessage, + }; + #[bench] fn bench_deserialize_rust_protobuf_bytes(b: &mut Bencher) { // Generate 4MB of data diff --git a/pb-test/src/pbtest.rs b/pb-test/src/pbtest.rs index a69bc48..67d7bb9 100644 --- a/pb-test/src/pbtest.rs +++ b/pb-test/src/pbtest.rs @@ -1,7 +1,11 @@ -use std::fs::metadata; -use std::fs::File; -use std::io::Cursor; -use std::io::Read; +use std::fs::{ + metadata, + File, +}; +use std::io::{ + Cursor, + Read, +}; use bytes::Bytes; use pb_jelly::extensions::Extensible; diff --git a/pb-test/src/verify_generated_files.rs b/pb-test/src/verify_generated_files.rs index 765bed6..6f2a905 100644 --- a/pb-test/src/verify_generated_files.rs +++ b/pb-test/src/verify_generated_files.rs @@ -1,5 +1,7 @@ -use std::env; -use std::fs; +use std::{ + env, + fs, +}; use pretty_assertions::assert_eq; use walkdir::WalkDir;