Skip to content

Commit 3661e26

Browse files
authored
refactor!: remove non-idiomatic From<&T> for T trait impls (#945)
1 parent 7f4bc44 commit 3661e26

32 files changed

Lines changed: 0 additions & 14914 deletions

cargo-typify/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ pub enum IdOrName {
7272
Id(uuid::Uuid),
7373
Name(Name),
7474
}
75-
impl From<&IdOrName> for IdOrName {
76-
fn from(value: &IdOrName) -> Self {
77-
value.clone()
78-
}
79-
}
8075
impl std::str::FromStr for IdOrName {
8176
type Err = &'static str;
8277
fn from_str(value: &str) -> Result<Self, &'static str> {
@@ -139,11 +134,6 @@ impl From<Name> for String {
139134
value.0
140135
}
141136
}
142-
impl From<&Name> for Name {
143-
fn from(value: &Name) -> Self {
144-
value.clone()
145-
}
146-
}
147137
impl std::str::FromStr for Name {
148138
type Err = &'static str;
149139
fn from_str(value: &str) -> Result<Self, &'static str> {

cargo-typify/tests/outputs/builder.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ impl ::std::convert::From<Fruit>
5858
value.0
5959
}
6060
}
61-
impl ::std::convert::From<&Fruit> for Fruit {
62-
fn from(value: &Fruit) -> Self {
63-
value.clone()
64-
}
65-
}
6661
impl ::std::convert::From<::std::collections::HashMap<::std::string::String, ::std::string::String>>
6762
for Fruit
6863
{
@@ -105,11 +100,6 @@ pub enum FruitOrVeg {
105100
Veg(Veggie),
106101
Fruit(Fruit),
107102
}
108-
impl ::std::convert::From<&Self> for FruitOrVeg {
109-
fn from(value: &FruitOrVeg) -> Self {
110-
value.clone()
111-
}
112-
}
113103
impl ::std::convert::From<Veggie> for FruitOrVeg {
114104
fn from(value: Veggie) -> Self {
115105
Self::Veg(value)
@@ -153,11 +143,6 @@ pub struct Veggie {
153143
#[serde(rename = "veggieName")]
154144
pub veggie_name: ::std::string::String,
155145
}
156-
impl ::std::convert::From<&Veggie> for Veggie {
157-
fn from(value: &Veggie) -> Self {
158-
value.clone()
159-
}
160-
}
161146
impl Veggie {
162147
pub fn builder() -> builder::Veggie {
163148
Default::default()
@@ -197,11 +182,6 @@ pub struct Veggies {
197182
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
198183
pub vegetables: ::std::vec::Vec<Veggie>,
199184
}
200-
impl ::std::convert::From<&Veggies> for Veggies {
201-
fn from(value: &Veggies) -> Self {
202-
value.clone()
203-
}
204-
}
205185
impl ::std::default::Default for Veggies {
206186
fn default() -> Self {
207187
Self {

cargo-typify/tests/outputs/custom_btree_map.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ impl ::std::convert::From<Fruit>
5858
value.0
5959
}
6060
}
61-
impl ::std::convert::From<&Fruit> for Fruit {
62-
fn from(value: &Fruit) -> Self {
63-
value.clone()
64-
}
65-
}
6661
impl
6762
::std::convert::From<::std::collections::BTreeMap<::std::string::String, ::std::string::String>>
6863
for Fruit
@@ -106,11 +101,6 @@ pub enum FruitOrVeg {
106101
Veg(Veggie),
107102
Fruit(Fruit),
108103
}
109-
impl ::std::convert::From<&Self> for FruitOrVeg {
110-
fn from(value: &FruitOrVeg) -> Self {
111-
value.clone()
112-
}
113-
}
114104
impl ::std::convert::From<Veggie> for FruitOrVeg {
115105
fn from(value: Veggie) -> Self {
116106
Self::Veg(value)
@@ -154,11 +144,6 @@ pub struct Veggie {
154144
#[serde(rename = "veggieName")]
155145
pub veggie_name: ::std::string::String,
156146
}
157-
impl ::std::convert::From<&Veggie> for Veggie {
158-
fn from(value: &Veggie) -> Self {
159-
value.clone()
160-
}
161-
}
162147
impl Veggie {
163148
pub fn builder() -> builder::Veggie {
164149
Default::default()
@@ -198,11 +183,6 @@ pub struct Veggies {
198183
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
199184
pub vegetables: ::std::vec::Vec<Veggie>,
200185
}
201-
impl ::std::convert::From<&Veggies> for Veggies {
202-
fn from(value: &Veggies) -> Self {
203-
value.clone()
204-
}
205-
}
206186
impl ::std::default::Default for Veggies {
207187
fn default() -> Self {
208188
Self {

cargo-typify/tests/outputs/derive.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ impl ::std::convert::From<Fruit>
5858
value.0
5959
}
6060
}
61-
impl ::std::convert::From<&Fruit> for Fruit {
62-
fn from(value: &Fruit) -> Self {
63-
value.clone()
64-
}
65-
}
6661
impl ::std::convert::From<::std::collections::HashMap<::std::string::String, ::std::string::String>>
6762
for Fruit
6863
{
@@ -105,11 +100,6 @@ pub enum FruitOrVeg {
105100
Veg(Veggie),
106101
Fruit(Fruit),
107102
}
108-
impl ::std::convert::From<&Self> for FruitOrVeg {
109-
fn from(value: &FruitOrVeg) -> Self {
110-
value.clone()
111-
}
112-
}
113103
impl ::std::convert::From<Veggie> for FruitOrVeg {
114104
fn from(value: Veggie) -> Self {
115105
Self::Veg(value)
@@ -153,11 +143,6 @@ pub struct Veggie {
153143
#[serde(rename = "veggieName")]
154144
pub veggie_name: ::std::string::String,
155145
}
156-
impl ::std::convert::From<&Veggie> for Veggie {
157-
fn from(value: &Veggie) -> Self {
158-
value.clone()
159-
}
160-
}
161146
#[doc = "A representation of a person, company, organization, or place"]
162147
#[doc = r""]
163148
#[doc = r" <details><summary>JSON schema</summary>"]
@@ -192,11 +177,6 @@ pub struct Veggies {
192177
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
193178
pub vegetables: ::std::vec::Vec<Veggie>,
194179
}
195-
impl ::std::convert::From<&Veggies> for Veggies {
196-
fn from(value: &Veggies) -> Self {
197-
value.clone()
198-
}
199-
}
200180
impl ::std::default::Default for Veggies {
201181
fn default() -> Self {
202182
Self {

cargo-typify/tests/outputs/multi_derive.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ impl ::std::convert::From<Fruit>
6060
value.0
6161
}
6262
}
63-
impl ::std::convert::From<&Fruit> for Fruit {
64-
fn from(value: &Fruit) -> Self {
65-
value.clone()
66-
}
67-
}
6863
impl ::std::convert::From<::std::collections::HashMap<::std::string::String, ::std::string::String>>
6964
for Fruit
7065
{
@@ -109,11 +104,6 @@ pub enum FruitOrVeg {
109104
Veg(Veggie),
110105
Fruit(Fruit),
111106
}
112-
impl ::std::convert::From<&Self> for FruitOrVeg {
113-
fn from(value: &FruitOrVeg) -> Self {
114-
value.clone()
115-
}
116-
}
117107
impl ::std::convert::From<Veggie> for FruitOrVeg {
118108
fn from(value: Veggie) -> Self {
119109
Self::Veg(value)
@@ -159,11 +149,6 @@ pub struct Veggie {
159149
#[serde(rename = "veggieName")]
160150
pub veggie_name: ::std::string::String,
161151
}
162-
impl ::std::convert::From<&Veggie> for Veggie {
163-
fn from(value: &Veggie) -> Self {
164-
value.clone()
165-
}
166-
}
167152
#[doc = "A representation of a person, company, organization, or place"]
168153
#[doc = r""]
169154
#[doc = r" <details><summary>JSON schema</summary>"]
@@ -200,11 +185,6 @@ pub struct Veggies {
200185
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
201186
pub vegetables: ::std::vec::Vec<Veggie>,
202187
}
203-
impl ::std::convert::From<&Veggies> for Veggies {
204-
fn from(value: &Veggies) -> Self {
205-
value.clone()
206-
}
207-
}
208188
impl ::std::default::Default for Veggies {
209189
fn default() -> Self {
210190
Self {

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ impl ::std::convert::From<Fruit>
5858
value.0
5959
}
6060
}
61-
impl ::std::convert::From<&Fruit> for Fruit {
62-
fn from(value: &Fruit) -> Self {
63-
value.clone()
64-
}
65-
}
6661
impl ::std::convert::From<::std::collections::HashMap<::std::string::String, ::std::string::String>>
6762
for Fruit
6863
{
@@ -105,11 +100,6 @@ pub enum FruitOrVeg {
105100
Veg(Veggie),
106101
Fruit(Fruit),
107102
}
108-
impl ::std::convert::From<&Self> for FruitOrVeg {
109-
fn from(value: &FruitOrVeg) -> Self {
110-
value.clone()
111-
}
112-
}
113103
impl ::std::convert::From<Veggie> for FruitOrVeg {
114104
fn from(value: Veggie) -> Self {
115105
Self::Veg(value)
@@ -153,11 +143,6 @@ pub struct Veggie {
153143
#[serde(rename = "veggieName")]
154144
pub veggie_name: ::std::string::String,
155145
}
156-
impl ::std::convert::From<&Veggie> for Veggie {
157-
fn from(value: &Veggie) -> Self {
158-
value.clone()
159-
}
160-
}
161146
#[doc = "A representation of a person, company, organization, or place"]
162147
#[doc = r""]
163148
#[doc = r" <details><summary>JSON schema</summary>"]
@@ -192,11 +177,6 @@ pub struct Veggies {
192177
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
193178
pub vegetables: ::std::vec::Vec<Veggie>,
194179
}
195-
impl ::std::convert::From<&Veggies> for Veggies {
196-
fn from(value: &Veggies) -> Self {
197-
value.clone()
198-
}
199-
}
200180
impl ::std::default::Default for Veggies {
201181
fn default() -> Self {
202182
Self {

typify-impl/src/enums.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,12 +1489,6 @@ mod tests {
14891489
Err(::std::string::String),
14901490
}
14911491

1492-
impl ::std::convert::From<&Self> for ResultX {
1493-
fn from(value: &ResultX) -> Self {
1494-
value.clone()
1495-
}
1496-
}
1497-
14981492
impl ::std::convert::From<u32> for ResultX {
14991493
fn from(value: u32) -> Self {
15001494
Self::Ok(value)
@@ -1541,12 +1535,6 @@ mod tests {
15411535
Err(::std::string::String),
15421536
}
15431537

1544-
impl ::std::convert::From<&Self> for ResultX {
1545-
fn from(value: &ResultX) -> Self {
1546-
value.clone()
1547-
}
1548-
}
1549-
15501538
impl ::std::convert::From<u32> for ResultX {
15511539
fn from(value: u32) -> Self {
15521540
Self::Ok(value)

typify-impl/src/type_entry.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,12 +1082,6 @@ impl TypeEntry {
10821082
#(#variants_decl)*
10831083
}
10841084

1085-
impl ::std::convert::From<&Self> for #type_name {
1086-
fn from(value: &#type_name) -> Self {
1087-
value.clone()
1088-
}
1089-
}
1090-
10911085
#simple_enum_impl
10921086
#default_impl
10931087
#untagged_newtype_from_string_impl
@@ -1204,12 +1198,6 @@ impl TypeEntry {
12041198
pub #prop_name: #prop_type,
12051199
)*
12061200
}
1207-
1208-
impl ::std::convert::From<&#type_name> for #type_name {
1209-
fn from(value: &#type_name) -> Self {
1210-
value.clone()
1211-
}
1212-
}
12131201
},
12141202
);
12151203

@@ -1677,12 +1665,6 @@ impl TypeEntry {
16771665
}
16781666
}
16791667

1680-
impl ::std::convert::From<&#type_name> for #type_name {
1681-
fn from(value: &#type_name) -> Self {
1682-
value.clone()
1683-
}
1684-
}
1685-
16861668
#default_impl
16871669
#constraint_impl
16881670
};

typify-impl/tests/generator.out

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ mod types {
5959
pub struct AllTheTraits {
6060
pub ok: ::std::string::String,
6161
}
62-
impl ::std::convert::From<&AllTheTraits> for AllTheTraits {
63-
fn from(value: &AllTheTraits) -> Self {
64-
value.clone()
65-
}
66-
}
6762
impl AllTheTraits {
6863
pub fn builder() -> builder::AllTheTraits {
6964
Default::default()
@@ -99,11 +94,6 @@ mod types {
9994
pub value1: ::std::string::String,
10095
pub value2: u64,
10196
}
102-
impl ::std::convert::From<&CompoundType> for CompoundType {
103-
fn from(value: &CompoundType) -> Self {
104-
value.clone()
105-
}
106-
}
10797
impl CompoundType {
10898
pub fn builder() -> builder::CompoundType {
10999
Default::default()
@@ -137,11 +127,6 @@ mod types {
137127
#[serde(default = "defaults::pair_b")]
138128
pub b: StringEnum,
139129
}
140-
impl ::std::convert::From<&Pair> for Pair {
141-
fn from(value: &Pair) -> Self {
142-
value.clone()
143-
}
144-
}
145130
impl ::std::default::Default for Pair {
146131
fn default() -> Self {
147132
Self {
@@ -188,11 +173,6 @@ mod types {
188173
Two,
189174
BuckleMyShoe,
190175
}
191-
impl ::std::convert::From<&Self> for StringEnum {
192-
fn from(value: &StringEnum) -> Self {
193-
value.clone()
194-
}
195-
}
196176
impl ::std::fmt::Display for StringEnum {
197177
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
198178
match *self {

0 commit comments

Comments
 (0)