From a689d49ba9a8b5c078eb8aad77e61cafd3f67046 Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Sat, 19 Sep 2026 10:10:08 -0700 Subject: [PATCH] stop emitting TryFrom<&str> and TryFrom for non-string newtypes An unconstrained newtype whose inner type has FromStr should only implement From and From<&str> if the inner type is a string. --- typify-impl/src/type_entry.rs | 20 ----------------- typify/tests/schemas/merged-schemas.rs | 24 --------------------- typify/tests/schemas/noisy-types.rs | 12 ----------- typify/tests/schemas/types-with-defaults.rs | 12 ----------- 4 files changed, 68 deletions(-) diff --git a/typify-impl/src/type_entry.rs b/typify-impl/src/type_entry.rs index 8c2d79b8..2881f555 100644 --- a/typify-impl/src/type_entry.rs +++ b/typify-impl/src/type_entry.rs @@ -1416,26 +1416,6 @@ impl TypeEntry { Ok(Self(value.parse()?)) } } - impl ::std::convert::TryFrom<&str> for #type_name { - type Error = <#inner_type_name as - ::std::str::FromStr>::Err; - - fn try_from(value: &str) -> - ::std::result::Result - { - value.parse() - } - } - impl ::std::convert::TryFrom for #type_name { - type Error = <#inner_type_name as - ::std::str::FromStr>::Err; - - fn try_from(value: String) -> - ::std::result::Result - { - value.parse() - } - } } }); diff --git a/typify/tests/schemas/merged-schemas.rs b/typify/tests/schemas/merged-schemas.rs index e7b92de4..25b39cf2 100644 --- a/typify/tests/schemas/merged-schemas.rs +++ b/typify/tests/schemas/merged-schemas.rs @@ -219,18 +219,6 @@ impl ::std::str::FromStr for MergeNumberBounds { Ok(Self(value.parse()?)) } } -impl ::std::convert::TryFrom<&str> for MergeNumberBounds { - type Error = ::Err; - fn try_from(value: &str) -> ::std::result::Result { - value.parse() - } -} -impl ::std::convert::TryFrom for MergeNumberBounds { - type Error = ::Err; - fn try_from(value: String) -> ::std::result::Result { - value.parse() - } -} #[doc = "`MergeStringBounds`"] #[derive(:: serde :: Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[serde(transparent)] @@ -314,18 +302,6 @@ impl ::std::str::FromStr for NarrowNumber { Ok(Self(value.parse()?)) } } -impl ::std::convert::TryFrom<&str> for NarrowNumber { - type Error = <::std::num::NonZeroU64 as ::std::str::FromStr>::Err; - fn try_from(value: &str) -> ::std::result::Result { - value.parse() - } -} -impl ::std::convert::TryFrom for NarrowNumber { - type Error = <::std::num::NonZeroU64 as ::std::str::FromStr>::Err; - fn try_from(value: String) -> ::std::result::Result { - value.parse() - } -} #[doc = "`OrderDependentMerge`"] #[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)] pub struct OrderDependentMerge { diff --git a/typify/tests/schemas/noisy-types.rs b/typify/tests/schemas/noisy-types.rs index a4184756..ac7a2f79 100644 --- a/typify/tests/schemas/noisy-types.rs +++ b/typify/tests/schemas/noisy-types.rs @@ -50,18 +50,6 @@ impl ::std::str::FromStr for IntegerBs { Ok(Self(value.parse()?)) } } -impl ::std::convert::TryFrom<&str> for IntegerBs { - type Error = ::Err; - fn try_from(value: &str) -> ::std::result::Result { - value.parse() - } -} -impl ::std::convert::TryFrom for IntegerBs { - type Error = ::Err; - fn try_from(value: String) -> ::std::result::Result { - value.parse() - } -} #[doc = "`ObjectBs`"] #[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug, Default)] pub struct ObjectBs { diff --git a/typify/tests/schemas/types-with-defaults.rs b/typify/tests/schemas/types-with-defaults.rs index 01a9572f..e50d4f9e 100644 --- a/typify/tests/schemas/types-with-defaults.rs +++ b/typify/tests/schemas/types-with-defaults.rs @@ -129,18 +129,6 @@ impl ::std::str::FromStr for UInt { Ok(Self(value.parse()?)) } } -impl ::std::convert::TryFrom<&str> for UInt { - type Error = ::Err; - fn try_from(value: &str) -> ::std::result::Result { - value.parse() - } -} -impl ::std::convert::TryFrom for UInt { - type Error = ::Err; - fn try_from(value: String) -> ::std::result::Result { - value.parse() - } -} #[doc = "`UIntContainer`"] #[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)] pub struct UIntContainer {