Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Self in impl From<&Self> for type #727

Merged
merged 1 commit into from
Dec 26, 2024
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
2 changes: 1 addition & 1 deletion cargo-typify/tests/outputs/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub enum FruitOrVeg {
Veg(Veggie),
Fruit(Fruit),
}
impl ::std::convert::From<&FruitOrVeg> for FruitOrVeg {
impl ::std::convert::From<&Self> for FruitOrVeg {
fn from(value: &FruitOrVeg) -> Self {
value.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion cargo-typify/tests/outputs/custom_btree_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub enum FruitOrVeg {
Veg(Veggie),
Fruit(Fruit),
}
impl ::std::convert::From<&FruitOrVeg> for FruitOrVeg {
impl ::std::convert::From<&Self> for FruitOrVeg {
fn from(value: &FruitOrVeg) -> Self {
value.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion cargo-typify/tests/outputs/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub enum FruitOrVeg {
Veg(Veggie),
Fruit(Fruit),
}
impl ::std::convert::From<&FruitOrVeg> for FruitOrVeg {
impl ::std::convert::From<&Self> for FruitOrVeg {
fn from(value: &FruitOrVeg) -> Self {
value.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion cargo-typify/tests/outputs/multi_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub enum FruitOrVeg {
Veg(Veggie),
Fruit(Fruit),
}
impl ::std::convert::From<&FruitOrVeg> for FruitOrVeg {
impl ::std::convert::From<&Self> for FruitOrVeg {
fn from(value: &FruitOrVeg) -> Self {
value.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion cargo-typify/tests/outputs/no-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub enum FruitOrVeg {
Veg(Veggie),
Fruit(Fruit),
}
impl ::std::convert::From<&FruitOrVeg> for FruitOrVeg {
impl ::std::convert::From<&Self> for FruitOrVeg {
fn from(value: &FruitOrVeg) -> Self {
value.clone()
}
Expand Down
5 changes: 2 additions & 3 deletions typify-impl/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ impl SchemaCache {
};
self.schemas
.iter()
.filter_map(|(schema, type_entry)| {
(&search_schema == schema).then(|| type_entry.clone())
})
.filter(|(schema, _)| &search_schema == schema)
.map(|(_, type_entry)| type_entry.clone())
.next()
}
}
4 changes: 2 additions & 2 deletions typify-impl/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ mod tests {
Err(::std::string::String),
}

impl ::std::convert::From<&ResultX> for ResultX {
impl ::std::convert::From<&Self> for ResultX {
fn from(value: &ResultX) -> Self {
value.clone()
}
Expand Down Expand Up @@ -1525,7 +1525,7 @@ mod tests {
Err(::std::string::String),
}

impl ::std::convert::From<&ResultX> for ResultX {
impl ::std::convert::From<&Self> for ResultX {
fn from(value: &ResultX) -> Self {
value.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion typify-impl/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ fn merge_so_instance_type(
) -> Result<Option<SingleOrVec<InstanceType>>, ()> {
match (a, b) {
(None, None) => Ok(None),
(None, other @ Some(_)) | (other @ Some(_), None) => Ok(other.map(Clone::clone)),
(None, other @ Some(_)) | (other @ Some(_), None) => Ok(other.cloned()),

// If each has a single type, it must match.
(Some(SingleOrVec::Single(aa)), Some(SingleOrVec::Single(bb))) => {
Expand Down
5 changes: 1 addition & 4 deletions typify-impl/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ impl TypeSpace {
// Gather up the properties that are required but for which we have no
// schema. In those cases any value will do.
let required_unspecified = validation.required.iter().filter_map(|prop_name| {
validation
.properties
.get(prop_name)
.is_none()
(!validation.properties.contains_key(prop_name))
.then_some((prop_name, &Schema::Bool(true)))
});

Expand Down
2 changes: 1 addition & 1 deletion typify-impl/src/type_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ impl TypeEntry {
#(#variants_decl)*
}

impl ::std::convert::From<&#type_name> for #type_name {
impl ::std::convert::From<&Self> for #type_name {
fn from(value: &#type_name) -> Self {
value.clone()
}
Expand Down
2 changes: 1 addition & 1 deletion typify-impl/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ fn value_for_struct_props(
let extra_value = serde_json::Value::Object(
map.clone()
.into_iter()
.filter(|(name, _)| prop_map.get(name).is_none())
.filter(|(name, _)| !prop_map.contains_key(name))
.collect(),
);

Expand Down
2 changes: 1 addition & 1 deletion typify-impl/tests/generator.out
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ mod types {
Two,
BuckleMyShoe,
}
impl ::std::convert::From<&StringEnum> for StringEnum {
impl ::std::convert::From<&Self> for StringEnum {
fn from(value: &StringEnum) -> Self {
value.clone()
}
Expand Down
Loading
Loading