Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions typify-impl/src/type_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,16 +1630,16 @@ impl TypeEntry {

// TODO: if a user were to derive schemars::JsonSchema, it
// wouldn't be accurate.
// The conversion work lives in TryFrom<&str>: the validation
// asserts what the type is, so it sits with the
// assertion-flavored conversions, and FromStr,
// TryFrom<String>, and Deserialize all delegate to it.
quote! {
impl ::std::str::FromStr for #type_name {
type Err = self::error::ConversionError;

fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
#max
#min
#pat

Ok(Self(value.to_string()))
::std::convert::TryFrom::try_from(value)
}
}
impl ::std::convert::TryFrom<&str> for #type_name {
Expand All @@ -1648,7 +1648,11 @@ impl TypeEntry {
fn try_from(value: &str) ->
::std::result::Result<Self, self::error::ConversionError>
{
value.parse()
#max
#min
#pat

Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<::std::string::String> for #type_name {
Expand All @@ -1657,7 +1661,7 @@ impl TypeEntry {
fn try_from(value: ::std::string::String) ->
::std::result::Result<Self, self::error::ConversionError>
{
value.parse()
::std::convert::TryFrom::try_from(value.as_str())
}
}

Expand All @@ -1668,8 +1672,9 @@ impl TypeEntry {
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
::std::convert::TryFrom::try_from(
::std::string::String::deserialize(deserializer)?,
)
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(
e.to_string(),
Expand Down
Loading
Loading