Skip to content

Commit

Permalink
refactor: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Calum4 committed Sep 10, 2024
1 parent ff114cd commit 35675f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
30 changes: 20 additions & 10 deletions utoipauto-core/src/discover.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::vec;

use crate::file_utils::{extract_module_name_from_path, parse_files};
use crate::token_utils::Parameters;
use quote::ToTokens;
use syn::meta::ParseNestedMeta;
use syn::{punctuated::Punctuated, Attribute, GenericParam, Item, ItemFn, Meta, Token, Type};
use syn::token::Comma;
use crate::file_utils::{extract_module_name_from_path, parse_files};
use crate::token_utils::Parameters;
use syn::{punctuated::Punctuated, Attribute, GenericParam, Item, ItemFn, Meta, Token, Type};

/// Discover everything from a file, will explore folder recursively
pub fn discover_from_file(
Expand Down Expand Up @@ -87,7 +87,8 @@ fn parse_module_items(
.collect(),
syn::Item::Struct(s) => parse_from_attr(
&s.attrs,
&build_path(module_path, &s.ident.to_string()),s.generics.params,
&build_path(module_path, &s.ident.to_string()),
s.generics.params,
imports.clone(),
params,
),
Expand Down Expand Up @@ -116,9 +117,7 @@ fn parse_from_attr(
params: &Parameters,
) -> Vec<DiscoverType> {
let mut out: Vec<DiscoverType> = vec![];
let is_non_lifetime_generic = !generic_params
.iter()
.all(|p| matches!(p, GenericParam::Lifetime(_)));
let is_non_lifetime_generic = !generic_params.iter().all(|p| matches!(p, GenericParam::Lifetime(_)));

for attr in a {
let meta = &attr.meta;
Expand Down Expand Up @@ -148,7 +147,12 @@ fn parse_from_attr(
}
if is_non_lifetime_generic && attr.path().is_ident("aliases") {
let _ = attr.parse_nested_meta(|meta| {
out.push(DiscoverType::Model(parse_generic_schema(meta, name, imports.clone(), &generic_params)));
out.push(DiscoverType::Model(parse_generic_schema(
meta,
name,
imports.clone(),
&generic_params,
)));

Ok(())
});
Expand All @@ -173,7 +177,10 @@ fn parse_generic_schema(
let mut generics = Vec::new();

for (index, part) in parts.iter().enumerate() {
match non_lifetime_generic_params.get(index).expect("Too few parameters provided to generic") {
match non_lifetime_generic_params
.get(index)
.expect("Too few parameters provided to generic")
{
GenericParam::Lifetime(_) => (),
_ => generics.push(part.to_string()),
};
Expand Down Expand Up @@ -202,7 +209,10 @@ fn parse_generic_schema(
let mut generics = Vec::new();

for (index, part) in parts.iter().enumerate() {
match non_lifetime_generic_params.get(index).expect("Too few parameters provided to generic") {
match non_lifetime_generic_params
.get(index)
.expect("Too few parameters provided to generic")
{
GenericParam::Lifetime(_) => (),
GenericParam::Type(_) => generics.push(process_one_generic(part, name, imports.clone())),
GenericParam::Const(_) => generics.push(part.to_string()),
Expand Down
6 changes: 3 additions & 3 deletions utoipauto/tests/default_features/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use utoipauto_macro::utoipauto;
)]
pub struct TypeGenericAndConstGenericStructSchema<T, const N: usize> {
foo: T,
bar: [u16; N]
bar: [u16; N],
}

/// Combined - lifetime & type
Expand All @@ -20,15 +20,15 @@ pub struct TypeGenericAndConstGenericStructSchema<T, const N: usize> {
)]
pub struct LifetimeAndTypeGenericGenericStructSchema<'a, T> {
foo: &'a str,
bar: T
bar: T,
}

/// Combined - lifetime & const
#[derive(utoipa::ToSchema)]
#[aliases(LifetimeAndConstGenericGenericStructSchema2 = LifetimeAndConstGenericGenericStructSchema<'a, 2>)]
pub struct LifetimeAndConstGenericGenericStructSchema<'a, const N: usize> {
foo: &'a str,
bar: [u16; N]
bar: [u16; N],
}

/// Combined - lifetime & const & type
Expand Down
4 changes: 2 additions & 2 deletions utoipauto/tests/default_features/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod const_generics;
pub mod controllers;
pub mod type_generics;
pub mod generics;
pub mod lifetime_generics;
pub mod models;
pub mod test;
pub mod generics;
pub mod type_generics;

0 comments on commit 35675f0

Please sign in to comment.