-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #17115 - leviska:json_is_not_rust_better_names, r=Veykril
Try to generate more meaningful names in json converter I just found out about rust-analyzer json converter, but I think it would be more convenient, if names were more useful, like using the names of the keys. Let's look at some realistic arbitrary json: ```json { "user": { "address": { "street": "Main St", "house": 3 }, "email": "example@example.com" } } ``` I think, new generated code is much easier to read and to edit, than the old: ```rust // Old struct Struct1{ house: i64, street: String } struct Struct2{ address: Struct1, email: String } struct Struct3{ user: Struct2 } // New struct Address1{ house: i64, street: String } struct User1{ address: Address1, email: String } struct Root1{ user: User1 } ``` Ideally, if we drop the numbers, I can see it being usable just as is (may be rename root) ```rust struct Address{ house: i64, street: String } struct User{ address: Address, email: String } struct Root{ user: User } ``` Sadly, we can't just drop them, because there can be multiple fields (recursive) with the same name, and we can't just easily retroactively add numbers if the name has 2 instances due to parsing being single pass. We could ignore the `1` and add number only if it's > 1, but I will leave this open to discussion and right now made it the simpler way In sum, even with numbers, I think this PR still helps in readability
- Loading branch information
Showing
1 changed file
with
66 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters