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
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ thiserror = "2.0.12"
trybuild = "1.0.104"
unicode-ident = "1.0.18"
uuid = "1.16.0"
criterion = "0.5.1"
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.80.1"
channel = "1.81.0"
profile = "default"
6 changes: 5 additions & 1 deletion typify-impl/src/type_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,10 +1527,14 @@ impl TypeEntry {
}
}
});

let pat = pattern.as_ref().map(|p| {
let err = format!("doesn't match pattern \"{}\"", p);
quote! {
if regress::Regex::new(#p).unwrap().find(value).is_none() {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> = ::std::sync::LazyLock::new(|| {
::regress::Regex::new(#p).unwrap()
});
if (&*PATTERN).find(value).is_none() {
return Err(#err.into());
}
}
Expand Down
78 changes: 32 additions & 46 deletions typify-impl/tests/vega.out
Original file line number Diff line number Diff line change
Expand Up @@ -22327,11 +22327,9 @@ impl ::std::convert::From<&DataVariant2FormatVariant0Subtype0ParseVariant1ValueV
impl ::std::str::FromStr for DataVariant2FormatVariant0Subtype0ParseVariant1ValueVariant1 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(date|utc):.*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(date|utc):.*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -22849,11 +22847,9 @@ impl ::std::convert::From<&DataVariant2FormatVariant0Subtype1ParseVariant1ValueV
impl ::std::str::FromStr for DataVariant2FormatVariant0Subtype1ParseVariant1ValueVariant1 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(date|utc):.*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(date|utc):.*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -23430,11 +23426,9 @@ impl ::std::convert::From<&DataVariant2FormatVariant0Subtype2ParseVariant1ValueV
impl ::std::str::FromStr for DataVariant2FormatVariant0Subtype2ParseVariant1ValueVariant1 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(date|utc):.*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(date|utc):.*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -24020,11 +24014,9 @@ impl ::std::convert::From<&DataVariant2FormatVariant0Subtype3ParseVariant1ValueV
impl ::std::str::FromStr for DataVariant2FormatVariant0Subtype3ParseVariant1ValueVariant1 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(date|utc):.*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(date|utc):.*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -25225,11 +25217,9 @@ impl ::std::convert::From<&DataVariant3FormatVariant0Subtype0ParseVariant1ValueV
impl ::std::str::FromStr for DataVariant3FormatVariant0Subtype0ParseVariant1ValueVariant1 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(date|utc):.*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(date|utc):.*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -25747,11 +25737,9 @@ impl ::std::convert::From<&DataVariant3FormatVariant0Subtype1ParseVariant1ValueV
impl ::std::str::FromStr for DataVariant3FormatVariant0Subtype1ParseVariant1ValueVariant1 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(date|utc):.*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(date|utc):.*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -26328,11 +26316,9 @@ impl ::std::convert::From<&DataVariant3FormatVariant0Subtype2ParseVariant1ValueV
impl ::std::str::FromStr for DataVariant3FormatVariant0Subtype2ParseVariant1ValueVariant1 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(date|utc):.*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(date|utc):.*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -26918,11 +26904,9 @@ impl ::std::convert::From<&DataVariant3FormatVariant0Subtype3ParseVariant1ValueV
impl ::std::str::FromStr for DataVariant3FormatVariant0Subtype3ParseVariant1ValueVariant1 {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(date|utc):.*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^(date|utc):.*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(date|utc):.*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -31398,7 +31382,9 @@ impl ::std::convert::From<&EncodeKey> for EncodeKey {
impl ::std::str::FromStr for EncodeKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^.+$").unwrap().find(value).is_none() {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^.+$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^.+$\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -107885,11 +107871,11 @@ impl ::std::convert::From<&TitleVariant1EncodeSubtype0Key> for TitleVariant1Enco
impl ::std::str::FromStr for TitleVariant1EncodeSubtype0Key {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^(?!interactive|name|style).+$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^(?!interactive|name|style).+$").unwrap()
});
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^(?!interactive|name|style).+$\"".into());
}
Ok(Self(value.to_string()))
Expand Down
13 changes: 11 additions & 2 deletions typify/tests/schemas/id-or-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ impl ::std::convert::From<&IdOrYoloYolo> for IdOrYoloYolo {
impl ::std::str::FromStr for IdOrYoloYolo {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new(".*").unwrap().find(value).is_none() {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new(".*").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \".*\"".into());
}
Ok(Self(value.to_string()))
Expand Down Expand Up @@ -403,7 +405,14 @@ impl ::std::str::FromStr for Name {
if value.chars().count() > 63usize {
return Err("longer than 63 characters".into());
}
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]$") . unwrap () . find (value) . is_none () { return Err ("doesn't match pattern \"^(?![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]$\"" . into ()) ; }
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 ()
},
);
if (&*PATTERN).find(value).is_none() {
return Err ("doesn't match pattern \"^(?![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]$\"" . into ()) ;
}
Ok(Self(value.to_string()))
}
}
Expand Down
8 changes: 3 additions & 5 deletions typify/tests/schemas/property-pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ impl ::std::convert::From<&TestGrammarForPatternPropertiesRulesKey>
impl ::std::str::FromStr for TestGrammarForPatternPropertiesRulesKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("^[a-zA-Z_]\\w*$")
.unwrap()
.find(value)
.is_none()
{
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^[a-zA-Z_]\\w*$").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"^[a-zA-Z_]\\w*$\"".into());
}
Ok(Self(value.to_string()))
Expand Down
4 changes: 3 additions & 1 deletion typify/tests/schemas/types-with-more-impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ impl ::std::convert::From<&PatternString> for PatternString {
impl ::std::str::FromStr for PatternString {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if regress::Regex::new("xx").unwrap().find(value).is_none() {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("xx").unwrap());
if (&*PATTERN).find(value).is_none() {
return Err("doesn't match pattern \"xx\"".into());
}
Ok(Self(value.to_string()))
Expand Down