diff --git a/CHANGELOG.md b/CHANGELOG.md index eec96428..316263c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.1] - 2022-01-11 + +### Changed +- The generated Rust code is now slightly more DRY. + ## [0.9.0] - 2022-01-11 ### Changed diff --git a/Cargo.lock b/Cargo.lock index ea8c3871..1f8e1673 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,7 +162,7 @@ dependencies = [ [[package]] name = "typical" -version = "0.9.0" +version = "0.9.1" dependencies = [ "clap", "colored", diff --git a/Cargo.toml b/Cargo.toml index 29826cdc..481d09ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "typical" -version = "0.9.0" +version = "0.9.1" authors = ["Stephan Boyer "] edition = "2021" description = "Algebraic data types for data interchange." diff --git a/src/generate_rust.rs b/src/generate_rust.rs index 58948375..5ebc5a30 100644 --- a/src/generate_rust.rs +++ b/src/generate_rust.rs @@ -95,6 +95,8 @@ use std::{{ mem::transmute, }}; +const MISSING_FIELDS_ERROR_MESSAGE: &str = \"Struct missing one or more required field(s).\"; + pub trait Serialize {{ fn size(&self) -> usize; @@ -638,7 +640,8 @@ fn write_schema( write_indentation(buffer, indentation + 4)?; writeln!(buffer, "::std::io::ErrorKind::InvalidData,")?; write_indentation(buffer, indentation + 4)?; - writeln!(buffer, "\"Struct missing one or more field(s).\",")?; + write_supers(buffer, indentation)?; + writeln!(buffer, "MISSING_FIELDS_ERROR_MESSAGE,")?; write_indentation(buffer, indentation + 3)?; writeln!(buffer, "));")?; write_indentation(buffer, indentation + 2)?; diff --git a/test_data/types.rs b/test_data/types.rs index 4f5caa4f..77b2df07 100644 --- a/test_data/types.rs +++ b/test_data/types.rs @@ -7,6 +7,8 @@ use std::{ mem::transmute, }; +const MISSING_FIELDS_ERROR_MESSAGE: &str = "Struct missing one or more required field(s)."; + pub trait Serialize { fn size(&self) -> usize; @@ -306,7 +308,7 @@ pub mod circular_dependency { if _x.is_none() { return Err(::std::io::Error::new( ::std::io::ErrorKind::InvalidData, - "Struct missing one or more field(s).", + super::super::super::MISSING_FIELDS_ERROR_MESSAGE, )); } @@ -470,7 +472,7 @@ pub mod circular_dependency { || _fallback.is_none() { return Err(::std::io::Error::new( ::std::io::ErrorKind::InvalidData, - "Struct missing one or more field(s).", + super::super::MISSING_FIELDS_ERROR_MESSAGE, )); } @@ -2755,7 +2757,7 @@ pub mod comprehensive { || _aa_required.is_none() { return Err(::std::io::Error::new( ::std::io::ErrorKind::InvalidData, - "Struct missing one or more field(s).", + super::super::MISSING_FIELDS_ERROR_MESSAGE, )); } @@ -7902,7 +7904,7 @@ pub mod schema_evolution { || _optional_to_required.is_none() { return Err(::std::io::Error::new( ::std::io::ErrorKind::InvalidData, - "Struct missing one or more field(s).", + super::super::MISSING_FIELDS_ERROR_MESSAGE, )); } @@ -8620,7 +8622,7 @@ pub mod schema_evolution { || _required_to_nonexistent.is_none() { return Err(::std::io::Error::new( ::std::io::ErrorKind::InvalidData, - "Struct missing one or more field(s).", + super::super::MISSING_FIELDS_ERROR_MESSAGE, )); } @@ -9197,7 +9199,7 @@ pub mod schema_evolution { if _x.is_none() { return Err(::std::io::Error::new( ::std::io::ErrorKind::InvalidData, - "Struct missing one or more field(s).", + super::super::MISSING_FIELDS_ERROR_MESSAGE, )); }