Use serde instead of specialization#579
Merged
sophiajt merged 7 commits intonushell:masterfrom Sep 3, 2019
Merged
Conversation
Contributor
|
🎉🎉 |
This was referenced Sep 9, 2019
est31
added a commit
to est31/nushell
that referenced
this pull request
Sep 9, 2019
Fixes nushell#627 Fixes a regression caused by nushell#579, specifically commit cc8872b . The code was intended to perform a comparison between the wanted output type and "Tagged<Value>" in order to be able to provide a special-cased path for Tagged<Value>. When I wrote the code, I used "name" as a variable name and only later realized that it shadowed the "name" param to the function, so I renamed it to type_name, but forgot to change the comparison. This broke the special-casing, as the name param only contains the name of the struct without generics (like "Tagged"), while `std::any::type_name` (in the current implementation) contains the full paths of the struct including all generic params (like "nu::object::meta::Tagged<nu::object::base::Value>").
Hofer-Julian
pushed a commit
to Hofer-Julian/nushell
that referenced
this pull request
Jan 27, 2023
* Add wrap-around merge * Update working_with_tables.md fixed code formatting * better spacing around pipes * Moved merging to cookbook * grammar * fixed command hyperlinks * add page to vuepress config Co-authored-by: Yethal <nosuchemail@email.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a continuation of #531 and #569 and concludes the series of PRs to get rid of specialization.
As #569 took care of
Option<>,Vec<>and bare bools, we only had to cover the following types:(list obtainable by the command
rg "\(Deserialize\)][^}]*\}" -U src/commands/* | rg ": .*: " | sed 's/^.*: //' | sort | uniq | sed 's/\(Option\|Vec\)<\(.*\)>/\2/;s/(\(.*\), \(.*\))/\1\n\2/;s/,$//;/bool/d' | sort | uniq)I chose an approach to first serialize the argument to json, to then deserialize it using serde. This way, the layout of the
Taggedstruct doesn't have to be hardcoded. The difficulty in this approach was recognizing the type that one has to serialize to: sometimes, the value has to be unwrapped to its contents, sometimesValueis expected or even an untaggedvalue::Block. These were special cased with type name based checks.With this PR, nushell is specialization free. 🎉🎉🎉
cc #362
The trait itself was kept as it's still useful. Also it's still used by the
trimcommand.