From d92f66d0b0e9316318af7421274a02f9cf452676 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Wed, 6 May 2020 18:41:10 +0200 Subject: [PATCH] Fix missed compile errors from refactoring in 33c84cb for psql --- asn1rs-model/src/gen/rust/async_psql.rs | 23 ++++++++----- asn1rs-model/src/gen/rust/psql.rs | 44 +++++++++++++++++------- asn1rs-model/src/gen/rust/shared_psql.rs | 2 +- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/asn1rs-model/src/gen/rust/async_psql.rs b/asn1rs-model/src/gen/rust/async_psql.rs index e946e9f8..64e36926 100644 --- a/asn1rs-model/src/gen/rust/async_psql.rs +++ b/asn1rs-model/src/gen/rust/async_psql.rs @@ -53,13 +53,13 @@ impl GeneratorSupplement for AsyncPsqlInserter { Self::append_retrieve_for_container_type(name, impl_scope); let fn_load = create_load_fn(impl_scope, true); - for (index, (variant, v_type)) in enumeration.variants().enumerate() { + for (index, variant) in enumeration.variants().enumerate() { let mut block = Block::new(&format!( "if row.try_get::>({})?.is_some()", index + 1 )); - Self::append_load_field(false, name, &mut block, index, "value", v_type); - block.line(&format!("return Ok({}::{}(value));", name, variant)); + Self::append_load_field(false, name, &mut block, index, "value", variant.r#type()); + block.line(&format!("return Ok({}::{}(value));", name, variant.name())); fn_load.push_block(block); } fn_load.line(format!("Err({}::Error::RowUnloadable)", MODULE_NAME)); @@ -70,15 +70,22 @@ impl GeneratorSupplement for AsyncPsqlInserter { data_enum_insert_statement(name, enumeration) )); let mut updated_variants = Vec::with_capacity(enumeration.len()); - for (variant, v_type) in enumeration.variants() { - let module_name = RustCodeGenerator::rust_module_name(variant); + for variant in enumeration.variants() { + let module_name = RustCodeGenerator::rust_module_name(variant.name()); fn_insert.line(&format!( "let {} = if let Self::{}(value) = self {{ Some({}value) }} else {{ None }};", module_name, - variant, - if v_type.is_primitive() { "*" } else { "" } + variant.name(), + if variant.r#type().is_primitive() { + "*" + } else { + "" + } + )); + updated_variants.push(( + module_name, + RustType::Option(Box::new(variant.r#type().clone())), )); - updated_variants.push((module_name, RustType::Option(Box::new(v_type.clone())))); } impl_insert_fn_content(false, false, name, &updated_variants[..], fn_insert); } diff --git a/asn1rs-model/src/gen/rust/psql.rs b/asn1rs-model/src/gen/rust/psql.rs index 2508e49a..0bc20bb2 100644 --- a/asn1rs-model/src/gen/rust/psql.rs +++ b/asn1rs-model/src/gen/rust/psql.rs @@ -302,22 +302,24 @@ impl PsqlInserter { fn impl_data_enum_insert_fn(function: &mut Function, name: &str, enumeration: &DataEnum) { let mut variables = Vec::with_capacity(enumeration.len()); - for (variant, rust) in enumeration.variants() { + for variant in enumeration.variants() { let variable = RustCodeGenerator::rust_field_name( - &RustCodeGenerator::rust_module_name(variant), + &RustCodeGenerator::rust_module_name(variant.name()), true, ); - let sql_primitive = Model::::is_primitive(rust); + let sql_primitive = Model::::is_primitive(variant.r#type()); variables.push(format!("&{}", variable)); let mut block_if = Block::new(&format!( "let {} = if let {}::{}(value) = self", - variable, name, variant + variable, + name, + variant.name() )); if sql_primitive { block_if.line(format!( "Some({})", - Self::wrap_for_insert_in_as_or_from_if_required("*value", rust) + Self::wrap_for_insert_in_as_or_from_if_required("*value", variant.r#type()) .unwrap_or_else(|| "value".to_string()) )); } else { @@ -595,15 +597,26 @@ impl PsqlInserter { .join(", ") )); let mut block = Block::new("match index"); - for (index, (variant, rust)) in enumeration.variants().enumerate() { - let mut block_case = - Block::new(&format!("{} => Ok({}::{}(", index + 1, name, variant,)); + for (index, variant) in enumeration.variants().enumerate() { + let mut block_case = Block::new(&format!( + "{} => Ok({}::{}(", + index + 1, + name, + variant.name() + )); - if Model::::is_primitive(rust.as_inner_type()) { - if let Some(wrap) = Self::wrap_for_query_in_as_or_from_if_required("", rust) { + if Model::::is_primitive(variant.r#type().as_inner_type()) { + if let Some(wrap) = + Self::wrap_for_query_in_as_or_from_if_required("", variant.r#type()) + { block_case.line(format!( "row.get_opt::<_, {}>({}).ok_or_else({}::no_result)??{}", - rust.as_inner_type().to_sql().to_rust().to_string(), + variant + .r#type() + .as_inner_type() + .to_sql() + .to_rust() + .to_string(), index + 1, ERROR_TYPE, wrap @@ -611,7 +624,12 @@ impl PsqlInserter { } else { block_case.line(format!( "row.get_opt::<_, {}>({}).ok_or_else({}::no_result)??", - rust.as_inner_type().to_sql().to_rust().to_string(), + variant + .r#type() + .as_inner_type() + .to_sql() + .to_rust() + .to_string(), index + 1, ERROR_TYPE )); @@ -619,7 +637,7 @@ impl PsqlInserter { } else { block_case.line(&format!( "{}::query_with(transaction, row.get({}))?", - rust.clone().into_inner_type().to_string(), + variant.r#type().clone().into_inner_type().to_string(), index + 1 )); } diff --git a/asn1rs-model/src/gen/rust/shared_psql.rs b/asn1rs-model/src/gen/rust/shared_psql.rs index 7a53c04d..5a6b51ab 100644 --- a/asn1rs-model/src/gen/rust/shared_psql.rs +++ b/asn1rs-model/src/gen/rust/shared_psql.rs @@ -45,7 +45,7 @@ pub(crate) fn data_enum_insert_statement(name: &str, enumeration: &DataEnum) -> name, enumeration .variants() - .map(|(name, _)| RustCodeGenerator::rust_module_name(name)) + .map(|variant| RustCodeGenerator::rust_module_name(variant.name())) .collect::>() .join(", "), enumeration