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

Make bincode_derive 0 dependencies #409

Merged
merged 24 commits into from
Oct 12, 2021

Conversation

VictorKoenders
Copy link
Contributor

@VictorKoenders VictorKoenders commented Oct 7, 2021

This PR removes syn, proc_macro2 and quote from bincode_derive.

We still have to keep proc_macro2 as a dev dependency as it is otherwise impossible to test the parser. This is automatically used instead of proc_macro when running tests.

The change is roughly split into 2 parts:

Parsing

Most of parsing is done in the derive/src/parse/ folder. This will generate the following types:

  • Visibility, not being used currently
  • DataType either Struct or Enum, with the name of the data type being parsed
  • Generics the generics part of the type, e.g. struct Foo<'a>
  • GenericConstraints the "where" part of the type

Generate

Generating the code implementation is done in either derive/src/derive_enum.rs and derive/src/derive_struct.rs.

This is supported by the structs in derive/src/generate. The most notable points of this module are:

  • StreamBuilder is a thin but friendly wrapper around TokenStream
  • Generator is the base type of the code generator. This has helper methods to generate implementations:
    • ImplFor is a helper struct for a single impl A for B construction. In this functions can be defined:
      • GenerateFnBody is a helper struct for a single function in the above impl. This is created with a callback to FnBuilder which helps set some properties. GenerateFnBody has a stream() function which returns StreamBuilder for the function.

The code is tested against the current cases in tests/derive.rs, however we'll need a lot more test cases before this PR can be merged.

For testing purposes, all generated code is outputted to the current target folder, under file name <struct/enum name>_Encodeable.rs and <struct/enum name>_Decodeable.rs. This can help with debugging.

@VictorKoenders VictorKoenders requested a review from ZoeyR October 7, 2021 13:39
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2021

Codecov Report

Merging #409 (6662918) into feature/deserde (cb23078) will decrease coverage by 21.19%.
The diff coverage is 44.87%.

Impacted file tree graph

@@                 Coverage Diff                  @@
##           feature/deserde     #409       +/-   ##
====================================================
- Coverage            87.68%   66.48%   -21.20%     
====================================================
  Files                   16       29       +13     
  Lines                  958     1886      +928     
====================================================
+ Hits                   840     1254      +414     
- Misses                 118      632      +514     
Impacted Files Coverage Δ
derive/src/derive_enum.rs 0.00% <0.00%> (ø)
derive/src/derive_struct.rs 0.00% <0.00%> (ø)
derive/src/generate/generate_fn.rs 0.00% <0.00%> (ø)
derive/src/generate/generator.rs 0.00% <0.00%> (ø)
derive/src/generate/impl_for.rs 0.00% <0.00%> (ø)
derive/src/generate/stream_builder.rs 0.00% <0.00%> (ø)
tests/derive.rs 100.00% <ø> (ø)
derive/src/lib.rs 7.69% <7.69%> (ø)
derive/src/error.rs 12.50% <13.79%> (ø)
derive/src/parse/generics.rs 66.94% <66.94%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb23078...6662918. Read the comment docs.

@ZoeyR
Copy link
Collaborator

ZoeyR commented Oct 12, 2021

Looks like this parser can't handle field attributes (i.e. #[serde(skip)]). It shouldn't be too bad to add them because as far as I can tell they can all be ignored.

@VictorKoenders VictorKoenders merged commit 484a9ce into feature/deserde Oct 12, 2021
@VictorKoenders VictorKoenders deleted the feature/deserde-desyn branch October 12, 2021 13:53
@VictorKoenders VictorKoenders mentioned this pull request Oct 12, 2021
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants