From e38d84a47aa3dcbfc15a8230077c0b45c6010070 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 20 Dec 2025 08:34:52 +0000 Subject: [PATCH] style!: use "Self" in generated code --- typify-impl/src/lib.rs | 8 +++---- typify-impl/src/merge.rs | 45 ++++++++++++++++++----------------- typify-impl/src/test_util.rs | 10 ++++---- typify-impl/src/type_entry.rs | 8 +++---- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/typify-impl/src/lib.rs b/typify-impl/src/lib.rs index 2f791ba2..76f0b6c0 100644 --- a/typify-impl/src/lib.rs +++ b/typify-impl/src/lib.rs @@ -154,17 +154,17 @@ pub(crate) enum Name { impl Name { pub fn into_option(self) -> Option { match self { - Name::Required(s) | Name::Suggested(s) => Some(s), - Name::Unknown => None, + Self::Required(s) | Self::Suggested(s) => Some(s), + Self::Unknown => None, } } pub fn append(&self, s: &str) -> Self { match self { - Name::Required(prefix) | Name::Suggested(prefix) => { + Self::Required(prefix) | Self::Suggested(prefix) => { Self::Suggested(format!("{}_{}", prefix, s)) } - Name::Unknown => Name::Unknown, + Self::Unknown => Self::Unknown, } } } diff --git a/typify-impl/src/merge.rs b/typify-impl/src/merge.rs index 8e9104de..d16faa42 100644 --- a/typify-impl/src/merge.rs +++ b/typify-impl/src/merge.rs @@ -1131,29 +1131,30 @@ trait Roughly { impl Roughly for schemars::schema::Schema { fn roughly(&self, other: &Self) -> bool { match (self, other) { - (Schema::Bool(a), Schema::Bool(b)) => a == b, - (Schema::Bool(false), _) | (_, Schema::Bool(false)) => false, - - (Schema::Bool(true), Schema::Object(other)) - | (Schema::Object(other), Schema::Bool(true)) => matches!( - other, - SchemaObject { - metadata: _, - instance_type: None, - format: None, - enum_values: None, - const_value: None, - subschemas: None, - number: None, - string: None, - array: None, - object: None, - reference: None, - extensions: _, - } - ), + (Self::Bool(a), Self::Bool(b)) => a == b, + (Self::Bool(false), _) | (_, Self::Bool(false)) => false, + + (Self::Bool(true), Self::Object(other)) | (Self::Object(other), Self::Bool(true)) => { + matches!( + other, + SchemaObject { + metadata: _, + instance_type: None, + format: None, + enum_values: None, + const_value: None, + subschemas: None, + number: None, + string: None, + array: None, + object: None, + reference: None, + extensions: _, + } + ) + } - (Schema::Object(a), Schema::Object(b)) => { + (Self::Object(a), Self::Object(b)) => { a.instance_type == b.instance_type && a.format == b.format && a.enum_values == b.enum_values diff --git a/typify-impl/src/test_util.rs b/typify-impl/src/test_util.rs index bbc2fd46..7ae10cdd 100644 --- a/typify-impl/src/test_util.rs +++ b/typify-impl/src/test_util.rs @@ -283,9 +283,9 @@ impl SynCompare for Variant { impl SynCompare for Fields { fn syn_cmp(&self, other: &Self, _: bool) -> Result<(), String> { match (self, other) { - (Fields::Named(a), Fields::Named(b)) => a.syn_cmp(b, false), - (Fields::Unnamed(a), Fields::Unnamed(b)) => a.syn_cmp(b, false), - (Fields::Unit, Fields::Unit) => Ok(()), + (Self::Named(a), Self::Named(b)) => a.syn_cmp(b, false), + (Self::Unnamed(a), Self::Unnamed(b)) => a.syn_cmp(b, false), + (Self::Unit, Self::Unit) => Ok(()), _ => Err("mismatched field types".to_string()), } } @@ -314,8 +314,8 @@ impl SynCompare for Field { impl SynCompare for Type { fn syn_cmp(&self, other: &Self, _: bool) -> Result<(), String> { match (self, other) { - (Type::Tuple(a), Type::Tuple(b)) => a.syn_cmp(b, false), - (Type::Path(a), Type::Path(b)) => a.syn_cmp(b, false), + (Self::Tuple(a), Self::Tuple(b)) => a.syn_cmp(b, false), + (Self::Path(a), Self::Path(b)) => a.syn_cmp(b, false), _ => Err(format!( "unexpected or mismatched type pair: {:?} {:?}", self, other diff --git a/typify-impl/src/type_entry.rs b/typify-impl/src/type_entry.rs index 72ba8a80..d35c6c09 100644 --- a/typify-impl/src/type_entry.rs +++ b/typify-impl/src/type_entry.rs @@ -546,7 +546,7 @@ impl From for TypeEntry { impl TypeEntry { pub(crate) fn new_native(type_name: S, impls: &[TypeSpaceImpl]) -> Self { - TypeEntry { + Self { details: TypeEntryDetails::Native(TypeEntryNative { type_name: type_name.to_string(), impls: impls.to_vec(), @@ -556,7 +556,7 @@ impl TypeEntry { } } pub(crate) fn new_native_params(type_name: S, params: &[TypeId]) -> Self { - TypeEntry { + Self { details: TypeEntryDetails::Native(TypeEntryNative { type_name: type_name.to_string(), impls: Default::default(), @@ -566,7 +566,7 @@ impl TypeEntry { } } pub(crate) fn new_boolean() -> Self { - TypeEntry { + Self { details: TypeEntryDetails::Boolean, extra_derives: Default::default(), } @@ -575,7 +575,7 @@ impl TypeEntry { TypeEntryDetails::Integer(type_name.to_string()).into() } pub(crate) fn new_float(type_name: S) -> Self { - TypeEntry { + Self { details: TypeEntryDetails::Float(type_name.to_string()), extra_derives: Default::default(), }