diff --git a/Cargo.lock b/Cargo.lock index 7a11ce4..dfcb974 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,6 +148,7 @@ dependencies = [ "paste", "proc-macro2", "quote", + "regex", "serde", "structopt", "strum 0.21.0", @@ -920,9 +921,9 @@ checksum = "67827e6ea8ee8a7c4a72227ef4fc08957040acffdb5f122733b24fa12daff41b" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mime" @@ -1188,9 +1189,21 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.2" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1a59b5d8e97dee33696bf13c5ba8ab85341c002922fba050069326b9c498974" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -1199,9 +1212,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "rustix" diff --git a/Cargo.toml b/Cargo.toml index 375909b..6733948 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ heck = "0.3" paste = "1.0" toml = "0.5" serde = { version = "1.0", features = ["derive"] } +regex = "1.10.4" [dev-dependencies] diff --git a/src/render/typ.rs b/src/render/typ.rs index 9ab1b17..66f58dc 100644 --- a/src/render/typ.rs +++ b/src/render/typ.rs @@ -1,8 +1,10 @@ use super::super::parse::{self, *}; use super::RenderContext; use anyhow::Result; +use lazy_static::lazy_static; use proc_macro2::TokenStream; use quote::*; +use regex::Regex; pub fn value_type_def_token( type_def: &parse::ValueTypeDef, @@ -23,6 +25,7 @@ pub fn value_type_def_token( parse::ValueTypeDef::List(list_value) => { let nullable = list_value.is_nullable; let inner_token = value_type_def_token(&list_value.inner, schema, render_context)?; + let inner_token = strip_box(inner_token); if nullable { quote! { Option>} @@ -99,3 +102,17 @@ fn type_def_token( }; Ok(result) } + +fn strip_box(input: TokenStream) -> TokenStream { + if let Some(captures) = BOX_REGEX.captures(&input.to_string()) { + if let Some(group) = captures.get(1) { + return group.as_str().parse().unwrap(); + } + } + + input +} + +lazy_static! { + static ref BOX_REGEX: Regex = Regex::new(r#"^Box < (.*) >$"#).unwrap(); +}