Skip to content

Commit

Permalink
Use type segments instead for spans
Browse files Browse the repository at this point in the history
  • Loading branch information
matzipan committed Jan 19, 2025
1 parent 5ddd617 commit 1979e9d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/lox-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,22 @@ fn deserializer_for_struct_with_named_fields(

// Unwrap is okay because we expect this span to come from the source code
let field_type_new = extract_type_path(&field.ty).unwrap();
let field_type = field_type_new.span().source_text().unwrap();

// Unwrap is okay becuase we always expect at least one type
let field_main_type = field_type_new.segments.iter()
.last()
.unwrap()
.ident
.to_string();

if field_name == "version" {
return handle_version_field(type_name, field);
}

let parser = match field_type.as_str() {
let parser = match field_main_type.as_str() {
"String" | "f64" | "i32" => {
let deserializer_for_kvn_type = generate_call_to_deserializer_for_kvn_type(
&field_type,
&field_main_type,
field_type_new,
&expected_kvn_name,
true,
Expand All @@ -557,7 +563,7 @@ fn deserializer_for_struct_with_named_fields(
"Vec" => generate_call_to_deserializer_for_vec_type(&expected_kvn_name, field)?,
_ => {

let condition_shortcut = match field_type.as_str() {
let condition_shortcut = match field_main_type.as_str() {
"String" => quote! {},
_ => quote! { ! #field_type_new::should_check_key_match() || },
};
Expand Down

0 comments on commit 1979e9d

Please sign in to comment.