-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
Conversation
…implemented lifetime dependencies
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Looks like this parser can't handle field attributes (i.e. |
…ade bincode_derive ignore attributes
This PR removes
syn
,proc_macro2
andquote
frombincode_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 ofproc_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 currentlyDataType
eitherStruct
orEnum
, with the name of the data type being parsedGenerics
the generics part of the type, e.g.struct Foo<'a>
GenericConstraints
the "where" part of the typeGenerate
Generating the code implementation is done in either
derive/src/derive_enum.rs
andderive/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 aroundTokenStream
Generator
is the base type of the code generator. This has helper methods to generate implementations:ImplFor
is a helper struct for a singleimpl A for B
construction. In this functions can be defined:GenerateFnBody
is a helper struct for a single function in the aboveimpl
. This is created with a callback toFnBuilder
which helps set some properties.GenerateFnBody
has astream()
function which returnsStreamBuilder
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.