diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 38223696..b112d7aa 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -15,6 +15,48 @@ https://github.com/oxidecomputer/typify/compare/v0.10.0-alpha.3\...HEAD[Full list of commits] +Type generation moves to the +https://github.com/oxidecomputer/typespace[typespace] crate. + +*Builder API* + +* `TypeSpaceSettings` retains settings that modify translation (`with_replacement`, + `with_patch`, `with_conversion`, `with_crate`, `with_unknown_crates`); + everything pertaining to rendering is specified in `typespace::Settings` + which can be reached through `map_typespace_settings`; `with_derive`, + `with_attr`, `with_struct_builder`, `with_map_type`, and `with_type_mod` are + gone, as is `MapType` +* `TypeSpace::to_stream` returns a `Result`; `to_codespace` gives the rendered + code as a `codespace::Codespace` and `to_typespace` produces the finished + `typespace::Typespace` +* The `Type`, `TypeDetails`, `TypeEnum`, `TypeStruct`, and `TypeNewtype` views + are gone; `TypeSpace::inserted_type` may be used for queries +* A derive name is parsed by `typespace`: a trait it models is handled as that + trait, any other path is a foreign derive written on every type; a bare name + that is neither is an error + +*Generated code* + +* Items are emitted in type-name order rather than in schema order +* Pattern checks compile the regex with the ECMA-262 `u` flag, as JSON Schema + specifies, so `\p{..}` and `\u{..}` escapes work; a pattern with an identity + escape the `u` flag forbids is now a generation error (#1103) +* A constrained string newtype does its validation in `TryFrom<&str>`, and a + non-string newtype no longer gets `TryFrom<&str>` or `TryFrom` + (#1078, #1079) +* The `error` module and shared default functions are emitted only when + something references them (#1080, #1082) +* The 2024 keyword `gen` is no longer used as an identifier (#1074) +* An `anyOf` construction with mixed types that previously generated an + unusable type now results in an error + +*Other* + +* A type named through `replace`, `convert`, or `x-rust-type` is assumed to + implement whatever the compiler can check rather than failing generation + for a trait typify cannot see (#1094) +* The minimum supported Rust version is 1.97 + == 0.10.0-alpha.3 (released 2026-10-14) https://github.com/oxidecomputer/typify/compare/v0.10.0-alpha.2\...v0.10.0-alpha.3[Full list of commits] diff --git a/Cargo.lock b/Cargo.lock index 3d8b021b..662377be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,7 +175,7 @@ dependencies = [ "schemars", "semver", "serde_json", - "syn 3.0.6", + "syn 3.0.9", "tempfile", "typify", ] @@ -240,7 +240,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -258,7 +258,7 @@ dependencies = [ "proc-macro2", "quote", "semver", - "syn 3.0.6", + "syn 3.0.9", "version-ranges", ] @@ -378,7 +378,7 @@ dependencies = [ "schemars", "serde", "serde_json", - "syn 3.0.6", + "syn 3.0.9", "typify", ] @@ -613,9 +613,9 @@ checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "log" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" [[package]] name = "memchr" @@ -748,7 +748,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0" dependencies = [ "proc-macro2", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -876,7 +876,7 @@ dependencies = [ "proc-macro2", "quote", "schema-derive", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -888,7 +888,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -949,7 +949,7 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -965,9 +965,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.151" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ "itoa", "memchr", @@ -1003,7 +1003,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -1076,9 +1076,9 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.6" +version = "3.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" dependencies = [ "proc-macro2", "quote", @@ -1130,11 +1130,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.20" +version = "2.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" dependencies = [ - "thiserror-impl 2.0.20", + "thiserror-impl 2.0.21", ] [[package]] @@ -1150,13 +1150,13 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.20" +version = "2.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -1298,9 +1298,9 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.121" +version = "1.0.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0cabaa10be1917331a313866bd94526343e03c77bcf69144b62b072ad35d47c" +checksum = "62db9c92d704393fbf2132041720cc80b689f2d3f28521015c2ac866223c11b8" dependencies = [ "glob", "serde", @@ -1313,9 +1313,9 @@ dependencies = [ [[package]] name = "typespace" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bfd314a399873b377783fb16852995be87d0d3bb574f9180bc1eb001604c089" +checksum = "4098cf680a26e9cd5186e4555de0b0afbe6a30e02ecbbc5f6fdf320d81aaec2a" dependencies = [ "codespace", "heck", @@ -1326,8 +1326,8 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 3.0.6", - "thiserror 2.0.20", + "syn 3.0.9", + "thiserror 2.0.21", ] [[package]] @@ -1368,8 +1368,8 @@ dependencies = [ "semver", "serde", "serde_json", - "syn 3.0.6", - "thiserror 2.0.20", + "syn 3.0.9", + "thiserror 2.0.21", "typespace", "unicode-ident", "uuid", @@ -1386,7 +1386,7 @@ dependencies = [ "serde", "serde_json", "serde_tokenstream", - "syn 3.0.6", + "syn 3.0.9", "typify-impl", ] @@ -1400,15 +1400,15 @@ dependencies = [ "schemars", "serde", "serde_json", - "syn 3.0.6", + "syn 3.0.9", "typify", ] [[package]] name = "unicode-ident" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" [[package]] name = "unicode-segmentation" diff --git a/Cargo.toml b/Cargo.toml index dfef315f..83eeb859 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,6 @@ syn = { version = "3.0.2", features = ["full"] } tempfile = "3.27.0" thiserror = "2.0.18" trybuild = "1.0.116" -typespace = "0.1.0" +typespace = "0.1.1" unicode-ident = "1.0.24" uuid = "1.16.0" diff --git a/cargo-typify/README.md b/cargo-typify/README.md index 4b6b3408..d63e5f9b 100644 --- a/cargo-typify/README.md +++ b/cargo-typify/README.md @@ -134,7 +134,7 @@ impl std::str::FromStr for Name { if value.len() > 63usize { return Err("longer than 63 characters"); } - if regress::Regex::new("^(?![0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)^[a-z][a-z0-9-]*[a-zA-Z0-9]$") + if regress::Regex::with_flags("^(?![0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)^[a-z][a-z0-9-]*[a-zA-Z0-9]$", "u") .unwrap() .find(value) .is_none() diff --git a/typify-impl/tests/vega.out b/typify-impl/tests/vega.out index 6c3dea2c..72d74e60 100644 --- a/typify-impl/tests/vega.out +++ b/typify-impl/tests/vega.out @@ -7165,7 +7165,9 @@ impl ::std::convert::TryFrom<&str> type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^(date|utc):.*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(date|utc):.*$\"".into()); } @@ -7451,7 +7453,9 @@ impl ::std::convert::TryFrom<&str> type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^(date|utc):.*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(date|utc):.*$\"".into()); } @@ -7779,7 +7783,9 @@ impl ::std::convert::TryFrom<&str> type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^(date|utc):.*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(date|utc):.*$\"".into()); } @@ -8112,7 +8118,9 @@ impl ::std::convert::TryFrom<&str> type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^(date|utc):.*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(date|utc):.*$\"".into()); } @@ -8635,7 +8643,9 @@ impl ::std::convert::TryFrom<&str> type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^(date|utc):.*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(date|utc):.*$\"".into()); } @@ -8921,7 +8931,9 @@ impl ::std::convert::TryFrom<&str> type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^(date|utc):.*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(date|utc):.*$\"".into()); } @@ -9249,7 +9261,9 @@ impl ::std::convert::TryFrom<&str> type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^(date|utc):.*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(date|utc):.*$\"".into()); } @@ -9582,7 +9596,9 @@ impl ::std::convert::TryFrom<&str> type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^(date|utc):.*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(date|utc):.*$\"".into()); } @@ -11176,7 +11192,7 @@ impl ::std::convert::TryFrom<&str> for EncodeKey { type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^.+$").unwrap()); + ::std::sync::LazyLock::new(|| ::regress::Regex::with_flags("^.+$", "u").unwrap()); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^.+$\"".into()); } @@ -42548,7 +42564,7 @@ impl ::std::convert::TryFrom<&str> for TitleObjectEncodeSubtype0Key { fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = ::std::sync::LazyLock::new(|| { - ::regress::Regex::new("^(?!interactive|name|style).+$").unwrap() + ::regress::Regex::with_flags("^(?!interactive|name|style).+$", "u").unwrap() }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^(?!interactive|name|style).+$\"".into()); diff --git a/typify/tests/schemas/id-or-name.rs b/typify/tests/schemas/id-or-name.rs index 1d3f2b13..0069c88c 100644 --- a/typify/tests/schemas/id-or-name.rs +++ b/typify/tests/schemas/id-or-name.rs @@ -177,7 +177,7 @@ impl ::std::convert::TryFrom<&str> for IdOrYoloYolo { type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new(".*").unwrap()); + ::std::sync::LazyLock::new(|| ::regress::Regex::with_flags(".*", "u").unwrap()); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \".*\"".into()); } @@ -232,7 +232,7 @@ impl ::std::convert::TryFrom<&str> for Name { } static PATTERN: ::std::sync::LazyLock<::regress::Regex> = ::std::sync::LazyLock::new( || { - :: regress :: Regex :: new ("^(?![0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)^[a-z][a-z0-9-]*[a-zA-Z0-9]$") . unwrap () + :: regress :: Regex :: with_flags ("^(?![0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)^[a-z][a-z0-9-]*[a-zA-Z0-9]$" , "u") . unwrap () }, ); if PATTERN.find(value).is_none() { diff --git a/typify/tests/schemas/merged-schemas.rs b/typify/tests/schemas/merged-schemas.rs index 25b39cf2..ba12f242 100644 --- a/typify/tests/schemas/merged-schemas.rs +++ b/typify/tests/schemas/merged-schemas.rs @@ -393,7 +393,7 @@ impl ::std::convert::TryFrom<&str> for TriplePattern { fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = ::std::sync::LazyLock::new(|| { - ::regress::Regex::new("(?=^[a-z].+$)(?=^.{4,8}$)(?=.+[a-z]$)").unwrap() + ::regress::Regex::with_flags("(?=^[a-z].+$)(?=^.{4,8}$)(?=.+[a-z]$)", "u").unwrap() }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"(?=^[a-z].+$)(?=^.{4,8}$)(?=.+[a-z]$)\"".into()); diff --git a/typify/tests/schemas/property-pattern.rs b/typify/tests/schemas/property-pattern.rs index 54652f5e..6f07646a 100644 --- a/typify/tests/schemas/property-pattern.rs +++ b/typify/tests/schemas/property-pattern.rs @@ -36,7 +36,9 @@ impl ::std::convert::TryFrom<&str> for TestGrammarForPatternPropertiesRulesKey { type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("^[a-zA-Z_]\\w*$").unwrap()); + ::std::sync::LazyLock::new(|| { + ::regress::Regex::with_flags("^[a-zA-Z_]\\w*$", "u").unwrap() + }); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"^[a-zA-Z_]\\w*$\"".into()); } diff --git a/typify/tests/schemas/types-with-more-impls.rs b/typify/tests/schemas/types-with-more-impls.rs index c996bee4..69a81957 100644 --- a/typify/tests/schemas/types-with-more-impls.rs +++ b/typify/tests/schemas/types-with-more-impls.rs @@ -24,7 +24,7 @@ impl ::std::convert::TryFrom<&str> for PatternString { type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new("xx").unwrap()); + ::std::sync::LazyLock::new(|| ::regress::Regex::with_flags("xx", "u").unwrap()); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \"xx\"".into()); } diff --git a/typify/tests/schemas/various-enums-json-schema.rs b/typify/tests/schemas/various-enums-json-schema.rs index 57540b41..862538ae 100644 --- a/typify/tests/schemas/various-enums-json-schema.rs +++ b/typify/tests/schemas/various-enums-json-schema.rs @@ -435,7 +435,7 @@ impl ::std::convert::TryFrom<&str> for Ipv4Net { type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new(".*").unwrap()); + ::std::sync::LazyLock::new(|| ::regress::Regex::with_flags(".*", "u").unwrap()); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \".*\"".into()); } @@ -496,7 +496,7 @@ impl ::std::convert::TryFrom<&str> for Ipv6Net { type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new(".*").unwrap()); + ::std::sync::LazyLock::new(|| ::regress::Regex::with_flags(".*", "u").unwrap()); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \".*\"".into()); } diff --git a/typify/tests/schemas/various-enums.rs b/typify/tests/schemas/various-enums.rs index 38a513f6..5e819ea7 100644 --- a/typify/tests/schemas/various-enums.rs +++ b/typify/tests/schemas/various-enums.rs @@ -386,7 +386,7 @@ impl ::std::convert::TryFrom<&str> for Ipv4Net { type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new(".*").unwrap()); + ::std::sync::LazyLock::new(|| ::regress::Regex::with_flags(".*", "u").unwrap()); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \".*\"".into()); } @@ -437,7 +437,7 @@ impl ::std::convert::TryFrom<&str> for Ipv6Net { type Error = self::error::ConversionError; fn try_from(value: &str) -> ::std::result::Result { static PATTERN: ::std::sync::LazyLock<::regress::Regex> = - ::std::sync::LazyLock::new(|| ::regress::Regex::new(".*").unwrap()); + ::std::sync::LazyLock::new(|| ::regress::Regex::with_flags(".*", "u").unwrap()); if PATTERN.find(value).is_none() { return Err("doesn't match pattern \".*\"".into()); }