Skip to content

Commit

Permalink
Organize imports with rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
goffrie committed Feb 12, 2024
1 parent 07f7882 commit 021f9ef
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion examples/src/zero_copy/main.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 2 additions & 4 deletions pb-jelly-gen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 14 additions & 15 deletions pb-jelly-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pb-jelly/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ use bytes::{
BufMut,
};

use crate::varint;
use crate::wire_format;

use super::{
ensure_split,
ensure_wire_format,
Expand All @@ -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)]
Expand Down
6 changes: 4 additions & 2 deletions pb-jelly/src/varint.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -93,9 +94,10 @@ pub fn ensure_read<B: Buf>(buf: &mut B) -> io::Result<u64> {

#[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<u8>| {
Expand Down
3 changes: 1 addition & 2 deletions pb-test/pb_test_gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
16 changes: 8 additions & 8 deletions pb-test/src/bench.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -17,10 +20,6 @@ mod benches {
VecData,
};
use serde::Deserialize;
use std::{
hint::black_box,
io::Cursor,
};
use test::Bencher;

#[bench]
Expand Down Expand Up @@ -279,17 +278,18 @@ 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,
Message,
};
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
Expand Down
12 changes: 8 additions & 4 deletions pb-test/src/pbtest.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 4 additions & 2 deletions pb-test/src/verify_generated_files.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::env;
use std::fs;
use std::{
env,
fs,
};

use pretty_assertions::assert_eq;
use walkdir::WalkDir;
Expand Down

0 comments on commit 021f9ef

Please sign in to comment.