Skip to content

Commit

Permalink
[#43] MR
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed Oct 28, 2023
1 parent 984e2ee commit c13858e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
26 changes: 9 additions & 17 deletions macro_ui/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use quote::ToTokens;
use syn::{DataEnum, Field, Fields, GenericArgument, Ident, PathArguments, Type};
use syn::PathArguments::AngleBracketed;
use syn::{DataEnum, Field, Fields, GenericArgument, Ident, Type};

pub fn get_field_type(field: &Field) -> Option<Ident> {
match &field.ty {
Expand All @@ -9,25 +10,16 @@ pub fn get_field_type(field: &Field) -> Option<Ident> {
}

pub fn get_option_type(field: &Field) -> Option<Ident> {
match &field.ty {
Type::Path(type_path) => {
if let Some(segment) = type_path.path.segments.first() {
return match &segment.arguments {
PathArguments::AngleBracketed(args) => {
if let Some(GenericArgument::Type(Type::Path(type_path))) =
args.args.first()
{
return type_path.path.segments.first().map(|s| s.ident.clone());
}
None
}
_ => None,
};
if let Some(Type::Path(type_path)) = &field.ty {

Check failure on line 13 in macro_ui/src/utils.rs

View workflow job for this annotation

GitHub Actions / Check

mismatched types

Check failure on line 13 in macro_ui/src/utils.rs

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types

Check failure on line 13 in macro_ui/src/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> macro_ui/src/utils.rs:13:12 | 13 | if let Some(Type::Path(type_path)) = &field.ty { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ --------- this expression has type `&syn::Type` | | | expected `Type`, found `Option<_>` | = note: expected enum `syn::Type` found enum `std::option::Option<_>`
if let Some(segment) = type_path.path.segments.first() {
if let Some(AngleBracketed(args)) = &segment.arguments {

Check failure on line 15 in macro_ui/src/utils.rs

View workflow job for this annotation

GitHub Actions / Check

mismatched types

Check failure on line 15 in macro_ui/src/utils.rs

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types

Check failure on line 15 in macro_ui/src/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> macro_ui/src/utils.rs:15:20 | 15 | if let Some(AngleBracketed(args)) = &segment.arguments { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ------------------ this expression has type `&syn::PathArguments` | | | expected `PathArguments`, found `Option<_>` | = note: expected enum `syn::PathArguments` found enum `std::option::Option<_>`
if let Some(GenericArgument::Type(Type::Path(type_path))) = args.args.first() {
return type_path.path.segments.first().map(|s| s.ident.clone());
}
}
None
}
_ => None,
}
None
}

pub fn is_integer(field: &Field) -> bool {
Expand Down
1 change: 1 addition & 0 deletions rpg_tools_rendering/examples/pants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn create(style: PantsStyle) -> (String, Pants) {
Pants {
style,
color: Color::Blue,
belt: None,
},
)
}
Expand Down

0 comments on commit c13858e

Please sign in to comment.