Skip to content

Commit e70c54b

Browse files
committed
style!: use "Self" in generated code
1 parent cdb2c8e commit e70c54b

22 files changed

Lines changed: 2066 additions & 2071 deletions

cargo-typify/tests/outputs/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub enum FruitOrVeg {
106106
Fruit(Fruit),
107107
}
108108
impl ::std::convert::From<&Self> for FruitOrVeg {
109-
fn from(value: &FruitOrVeg) -> Self {
109+
fn from(value: &Self) -> Self {
110110
value.clone()
111111
}
112112
}

cargo-typify/tests/outputs/custom_btree_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub enum FruitOrVeg {
107107
Fruit(Fruit),
108108
}
109109
impl ::std::convert::From<&Self> for FruitOrVeg {
110-
fn from(value: &FruitOrVeg) -> Self {
110+
fn from(value: &Self) -> Self {
111111
value.clone()
112112
}
113113
}

cargo-typify/tests/outputs/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub enum FruitOrVeg {
106106
Fruit(Fruit),
107107
}
108108
impl ::std::convert::From<&Self> for FruitOrVeg {
109-
fn from(value: &FruitOrVeg) -> Self {
109+
fn from(value: &Self) -> Self {
110110
value.clone()
111111
}
112112
}

cargo-typify/tests/outputs/multi_derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub enum FruitOrVeg {
110110
Fruit(Fruit),
111111
}
112112
impl ::std::convert::From<&Self> for FruitOrVeg {
113-
fn from(value: &FruitOrVeg) -> Self {
113+
fn from(value: &Self) -> Self {
114114
value.clone()
115115
}
116116
}

cargo-typify/tests/outputs/no-builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub enum FruitOrVeg {
106106
Fruit(Fruit),
107107
}
108108
impl ::std::convert::From<&Self> for FruitOrVeg {
109-
fn from(value: &FruitOrVeg) -> Self {
109+
fn from(value: &Self) -> Self {
110110
value.clone()
111111
}
112112
}

typify-impl/src/enums.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ mod tests {
14901490
}
14911491

14921492
impl ::std::convert::From<&Self> for ResultX {
1493-
fn from(value: &ResultX) -> Self {
1493+
fn from(value: &Self) -> Self {
14941494
value.clone()
14951495
}
14961496
}
@@ -1542,7 +1542,7 @@ mod tests {
15421542
}
15431543

15441544
impl ::std::convert::From<&Self> for ResultX {
1545-
fn from(value: &ResultX) -> Self {
1545+
fn from(value: &Self) -> Self {
15461546
value.clone()
15471547
}
15481548
}

typify-impl/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,17 @@ pub(crate) enum Name {
154154
impl Name {
155155
pub fn into_option(self) -> Option<String> {
156156
match self {
157-
Name::Required(s) | Name::Suggested(s) => Some(s),
158-
Name::Unknown => None,
157+
Self::Required(s) | Self::Suggested(s) => Some(s),
158+
Self::Unknown => None,
159159
}
160160
}
161161

162162
pub fn append(&self, s: &str) -> Self {
163163
match self {
164-
Name::Required(prefix) | Name::Suggested(prefix) => {
164+
Self::Required(prefix) | Self::Suggested(prefix) => {
165165
Self::Suggested(format!("{}_{}", prefix, s))
166166
}
167-
Name::Unknown => Name::Unknown,
167+
Self::Unknown => Self::Unknown,
168168
}
169169
}
170170
}

typify-impl/src/merge.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,29 +1131,30 @@ trait Roughly {
11311131
impl Roughly for schemars::schema::Schema {
11321132
fn roughly(&self, other: &Self) -> bool {
11331133
match (self, other) {
1134-
(Schema::Bool(a), Schema::Bool(b)) => a == b,
1135-
(Schema::Bool(false), _) | (_, Schema::Bool(false)) => false,
1136-
1137-
(Schema::Bool(true), Schema::Object(other))
1138-
| (Schema::Object(other), Schema::Bool(true)) => matches!(
1139-
other,
1140-
SchemaObject {
1141-
metadata: _,
1142-
instance_type: None,
1143-
format: None,
1144-
enum_values: None,
1145-
const_value: None,
1146-
subschemas: None,
1147-
number: None,
1148-
string: None,
1149-
array: None,
1150-
object: None,
1151-
reference: None,
1152-
extensions: _,
1153-
}
1154-
),
1134+
(Self::Bool(a), Self::Bool(b)) => a == b,
1135+
(Self::Bool(false), _) | (_, Self::Bool(false)) => false,
1136+
1137+
(Self::Bool(true), Self::Object(other)) | (Self::Object(other), Self::Bool(true)) => {
1138+
matches!(
1139+
other,
1140+
SchemaObject {
1141+
metadata: _,
1142+
instance_type: None,
1143+
format: None,
1144+
enum_values: None,
1145+
const_value: None,
1146+
subschemas: None,
1147+
number: None,
1148+
string: None,
1149+
array: None,
1150+
object: None,
1151+
reference: None,
1152+
extensions: _,
1153+
}
1154+
)
1155+
}
11551156

1156-
(Schema::Object(a), Schema::Object(b)) => {
1157+
(Self::Object(a), Self::Object(b)) => {
11571158
a.instance_type == b.instance_type
11581159
&& a.format == b.format
11591160
&& a.enum_values == b.enum_values

typify-impl/src/test_util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ impl SynCompare for Variant {
283283
impl SynCompare for Fields {
284284
fn syn_cmp(&self, other: &Self, _: bool) -> Result<(), String> {
285285
match (self, other) {
286-
(Fields::Named(a), Fields::Named(b)) => a.syn_cmp(b, false),
287-
(Fields::Unnamed(a), Fields::Unnamed(b)) => a.syn_cmp(b, false),
288-
(Fields::Unit, Fields::Unit) => Ok(()),
286+
(Self::Named(a), Self::Named(b)) => a.syn_cmp(b, false),
287+
(Self::Unnamed(a), Self::Unnamed(b)) => a.syn_cmp(b, false),
288+
(Self::Unit, Self::Unit) => Ok(()),
289289
_ => Err("mismatched field types".to_string()),
290290
}
291291
}
@@ -314,8 +314,8 @@ impl SynCompare for Field {
314314
impl SynCompare for Type {
315315
fn syn_cmp(&self, other: &Self, _: bool) -> Result<(), String> {
316316
match (self, other) {
317-
(Type::Tuple(a), Type::Tuple(b)) => a.syn_cmp(b, false),
318-
(Type::Path(a), Type::Path(b)) => a.syn_cmp(b, false),
317+
(Self::Tuple(a), Self::Tuple(b)) => a.syn_cmp(b, false),
318+
(Self::Path(a), Self::Path(b)) => a.syn_cmp(b, false),
319319
_ => Err(format!(
320320
"unexpected or mismatched type pair: {:?} {:?}",
321321
self, other

typify-impl/src/type_entry.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl From<TypeEntryDetails> for TypeEntry {
546546

547547
impl TypeEntry {
548548
pub(crate) fn new_native<S: ToString>(type_name: S, impls: &[TypeSpaceImpl]) -> Self {
549-
TypeEntry {
549+
Self {
550550
details: TypeEntryDetails::Native(TypeEntryNative {
551551
type_name: type_name.to_string(),
552552
impls: impls.to_vec(),
@@ -556,7 +556,7 @@ impl TypeEntry {
556556
}
557557
}
558558
pub(crate) fn new_native_params<S: ToString>(type_name: S, params: &[TypeId]) -> Self {
559-
TypeEntry {
559+
Self {
560560
details: TypeEntryDetails::Native(TypeEntryNative {
561561
type_name: type_name.to_string(),
562562
impls: Default::default(),
@@ -566,7 +566,7 @@ impl TypeEntry {
566566
}
567567
}
568568
pub(crate) fn new_boolean() -> Self {
569-
TypeEntry {
569+
Self {
570570
details: TypeEntryDetails::Boolean,
571571
extra_derives: Default::default(),
572572
}
@@ -575,7 +575,7 @@ impl TypeEntry {
575575
TypeEntryDetails::Integer(type_name.to_string()).into()
576576
}
577577
pub(crate) fn new_float<S: ToString>(type_name: S) -> Self {
578-
TypeEntry {
578+
Self {
579579
details: TypeEntryDetails::Float(type_name.to_string()),
580580
extra_derives: Default::default(),
581581
}
@@ -1083,7 +1083,7 @@ impl TypeEntry {
10831083
}
10841084

10851085
impl ::std::convert::From<&Self> for #type_name {
1086-
fn from(value: &#type_name) -> Self {
1086+
fn from(value: &Self) -> Self {
10871087
value.clone()
10881088
}
10891089
}

0 commit comments

Comments
 (0)