Skip to content

Commit

Permalink
fix: trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Millione committed Aug 9, 2023
1 parent 32b720e commit 200961e
Show file tree
Hide file tree
Showing 30 changed files with 96 additions and 1,534 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pilota-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 6 additions & 5 deletions pilota-build/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use itertools::Itertools;
use normpath::PathExt;
use pkg_tree::PkgNode;
use quote::quote;
use rayon::prelude::IntoParallelRefIterator;
use rayon::{
prelude::{IntoParallelRefIterator, ParallelIterator},
str::ParallelString,
};
use traits::CodegenBackend;

use self::workspace::Workspace;
Expand Down Expand Up @@ -429,8 +432,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);
Expand Down Expand Up @@ -504,9 +505,9 @@ where
#![allow(warnings, clippy::all)]
{stream}
}}"#};

let stream = stream.par_lines().map(|s| s.trim()).collect::<String>();
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)
}
Expand Down
4 changes: 2 additions & 2 deletions pilota-build/src/codegen/thrift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 6 additions & 1 deletion pilota-build/src/codegen/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use anyhow::bail;
use faststr::FastStr;
use fxhash::FxHashMap;
use itertools::Itertools;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use rayon::{
prelude::{IntoParallelRefIterator, ParallelIterator},
str::ParallelString,
};

use super::CodegenItem;
use crate::{
Expand Down Expand Up @@ -287,6 +290,8 @@ where
stream.push_str(&format!("pub use {}::*;", main_mod_path.join("::")));
}

let stream = stream.par_lines().map(|s| s.trim()).collect::<String>();

let src_file = base_dir.as_ref().join(&*info.name).join("src/lib.rs");

std::fs::write(&src_file, stream)?;
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
14 changes: 0 additions & 14 deletions pilota-build/test_data/must_gen_items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod must_gen_items {
#![allow(warnings, clippy::all)]

pub mod must_gen_items {
#[derive(PartialOrd, Hash, Eq, Ord, Debug, Default, Clone, PartialEq)]
pub struct A {
Expand All @@ -15,7 +14,6 @@ pub mod must_gen_items {
#[allow(unused_imports)]
use ::pilota::thrift::TOutputProtocolExt;
let struct_ident = ::pilota::thrift::TStructIdentifier { name: "A" };

protocol.write_struct_begin(&struct_ident)?;
if let Some(value) = self.a.as_ref() {
protocol.write_i32_field(1, *value)?;
Expand All @@ -24,17 +22,13 @@ pub mod must_gen_items {
protocol.write_struct_end()?;
Ok(())
}

fn decode<T: ::pilota::thrift::TInputProtocol>(
protocol: &mut T,
) -> ::std::result::Result<Self, ::pilota::thrift::DecodeError> {
#[allow(unused_imports)]
use ::pilota::{thrift::TLengthProtocolExt, Buf};

let mut a = None;

let mut __pilota_decoding_field_id = None;

protocol.read_struct_begin()?;
if let Err(err) = (|| {
loop {
Expand All @@ -54,7 +48,6 @@ pub mod must_gen_items {
protocol.skip(field_ident.field_type)?;
}
}

protocol.read_field_end()?;
protocol.field_end_len();
}
Expand All @@ -72,18 +65,14 @@ pub mod must_gen_items {
}
};
protocol.read_struct_end()?;

let data = Self { a };
Ok(data)
}

async fn decode_async<T: ::pilota::thrift::TAsyncInputProtocol>(
protocol: &mut T,
) -> ::std::result::Result<Self, ::pilota::thrift::DecodeError> {
let mut a = None;

let mut __pilota_decoding_field_id = None;

protocol.read_struct_begin().await?;
if let Err(err) = async {
loop {
Expand All @@ -101,7 +90,6 @@ pub mod must_gen_items {
protocol.skip(field_ident.field_type).await?;
}
}

protocol.read_field_end().await?;
}
Ok::<_, ::pilota::thrift::DecodeError>(())
Expand All @@ -120,11 +108,9 @@ pub mod must_gen_items {
}
};
protocol.read_struct_end().await?;

let data = Self { a };
Ok(data)
}

fn size<T: ::pilota::thrift::TLengthProtocol>(&self, protocol: &mut T) -> usize {
#[allow(unused_imports)]
use ::pilota::thrift::TLengthProtocolExt;
Expand Down
Loading

0 comments on commit 200961e

Please sign in to comment.