Skip to content

Commit

Permalink
Apply customized cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem-Romanenia committed Sep 4, 2024
1 parent be437b4 commit 66306bd
Show file tree
Hide file tree
Showing 87 changed files with 1,304 additions and 5,662 deletions.
8 changes: 2 additions & 6 deletions o2o-impl/benches/o2o_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ fn derive_simple_benchmark(c: &mut Criterion) {
};

let input: DeriveInput = syn::parse2(tokens).unwrap();
c.bench_function("derive_simple_benchmark", |b| {
b.iter(|| derive(black_box(&input.clone())))
});
c.bench_function("derive_simple_benchmark", |b| b.iter(|| derive(black_box(&input.clone()))));
}

fn derive_complex_benchmark(c: &mut Criterion) {
Expand Down Expand Up @@ -59,9 +57,7 @@ fn derive_complex_benchmark(c: &mut Criterion) {
};

let input: DeriveInput = syn::parse2(tokens).unwrap();
c.bench_function("derive_complex_benchmark", |b| {
b.iter(|| derive(black_box(&input.clone())))
});
c.bench_function("derive_complex_benchmark", |b| b.iter(|| derive(black_box(&input.clone()))));
}

criterion_group!(benches, derive_simple_benchmark, derive_complex_benchmark);
Expand Down
43 changes: 8 additions & 35 deletions o2o-impl/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use proc_macro2::Span;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::token::Comma;
use syn::{
Attribute, DataEnum, DataStruct, DeriveInput, Fields, Generics, Ident, Index, Member, Result,
};
use syn::{Attribute, DataEnum, DataStruct, DeriveInput, Fields, Generics, Ident, Index, Member, Result};

#[derive(Default)]
struct Context {
Expand Down Expand Up @@ -59,9 +57,7 @@ impl<'a> Field {

if let Some(repeat_attr) = &field.attrs.repeat {
if ctx.field_attrs_to_repeat.is_some() && !field.attrs.stop_repeat {
panic!(
"Previous #[repeat] instruction must be terminated with #[stop_repeat]"
)
panic!("Previous #[repeat] instruction must be terminated with #[stop_repeat]")
}

ctx.field_attrs_to_repeat = Some((field.attrs.clone(), repeat_attr.permeate));
Expand All @@ -78,12 +74,7 @@ impl<'a> Field {
Ok(Field {
attrs: attr::get_member_attrs(SynDataTypeMember::Field(node), bark)?,
idx: i,
member: node.ident.clone().map(Member::Named).unwrap_or_else(|| {
Member::Unnamed(Index {
index: i as u32,
span: node.ty.span(),
})
}),
member: node.ident.clone().map(Member::Named).unwrap_or_else(|| Member::Unnamed(Index { index: i as u32, span: node.ty.span() })),
})
}
}
Expand All @@ -99,12 +90,7 @@ impl<'a> Enum<'a> {
pub fn from_syn(node: &'a DeriveInput, data: &'a DataEnum) -> Result<Self> {
let (attrs, bark) = attr::get_data_type_attrs(&node.attrs)?;
let variants = Variant::multiple_from_syn(&data.variants, bark)?;
Ok(Enum {
attrs,
ident: &node.ident,
generics: &node.generics,
variants,
})
Ok(Enum { attrs, ident: &node.ident, generics: &node.generics, variants })
}
}

Expand All @@ -118,14 +104,8 @@ pub(crate) struct Variant {
}

impl<'a> Variant {
fn multiple_from_syn(
variants: &'a Punctuated<syn::Variant, Comma>,
bark: bool,
) -> Result<Vec<Self>> {
let mut ctx = Context {
variant_attrs_to_repeat: None,
field_attrs_to_repeat: None,
};
fn multiple_from_syn(variants: &'a Punctuated<syn::Variant, Comma>, bark: bool) -> Result<Vec<Self>> {
let mut ctx = Context { variant_attrs_to_repeat: None, field_attrs_to_repeat: None };

variants
.iter()
Expand All @@ -139,9 +119,7 @@ impl<'a> Variant {

if variant.attrs.repeat.is_some() {
if ctx.variant_attrs_to_repeat.is_some() && !variant.attrs.stop_repeat {
panic!(
"Previous #[repeat] instruction must be terminated with #[stop_repeat]"
)
panic!("Previous #[repeat] instruction must be terminated with #[stop_repeat]")
}

ctx.variant_attrs_to_repeat = Some(variant.attrs.clone());
Expand All @@ -154,12 +132,7 @@ impl<'a> Variant {
.collect()
}

fn from_syn(
ctx: &mut Context,
i: usize,
variant: &'a syn::Variant,
bark: bool,
) -> Result<Self> {
fn from_syn(ctx: &mut Context, i: usize, variant: &'a syn::Variant, bark: bool) -> Result<Self> {
let fields = Field::multiple_from_syn(ctx, &variant.fields, bark)?;
let attrs = attr::get_member_attrs(SynDataTypeMember::Variant(variant), bark)?;

Expand Down
Loading

0 comments on commit 66306bd

Please sign in to comment.