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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ca98a36
started working on removing syn and quote
VictorKoenders Sep 26, 2021
2c7b822
Made tarpaulin run on the derive crate as well
VictorKoenders Sep 26, 2021
7a2fdb0
Made proc-macro2 a dev dependency in bincode derive
VictorKoenders Sep 27, 2021
975fea6
Split out the `read_tokens_until_punct` method so it can be re-used, …
VictorKoenders Sep 28, 2021
4409ab3
Added struct body parsing
VictorKoenders Sep 28, 2021
e97b079
Added the ability to parse enum bodies
VictorKoenders Sep 28, 2021
e4c7cb1
Re-added struct encode generation
VictorKoenders Sep 28, 2021
dad543b
Enabled tuple struct encodable test
VictorKoenders Sep 28, 2021
3834f24
Started working on a generator helper
VictorKoenders Sep 28, 2021
d31569a
Rewrote bincode_derive's code generator, implemented struct generate_…
VictorKoenders Oct 6, 2021
92e46bd
Made the code generator of bincode_derive friendlier to use
VictorKoenders Oct 7, 2021
7c7e31f
Implemented bincode_derive enum Encodable attribute
VictorKoenders Oct 7, 2021
83c8bb8
Made bincode_derive Field::type not Option
VictorKoenders Oct 7, 2021
daf111c
Implemented enum Decode
VictorKoenders Oct 7, 2021
286f296
Reworked bincode_derive to use StreamBuilder instead of TokenStream d…
VictorKoenders Oct 7, 2021
84f6abe
Reworked enum variant/struct fields to always be the same
VictorKoenders Oct 8, 2021
43d1d95
Removed assert in bincode_derive
VictorKoenders Oct 8, 2021
552d465
Removed commented out code
VictorKoenders Oct 8, 2021
132221c
Added a Span location to IdentOrIndex::Index
VictorKoenders Oct 8, 2021
c4a53e0
Reworked FnBuilder to be more in line with the rest of the generator
VictorKoenders Oct 8, 2021
395a13c
Removed commented out code
VictorKoenders Oct 12, 2021
6662918
Removed Sized constraint on Decodable trait
VictorKoenders Oct 12, 2021
855f833
Added a test to validate bincode_derive and serde working together. M…
VictorKoenders Oct 12, 2021
cfe6ebc
Fixed a corner case in derive/src/pparse/attributes.rs, fixed formatting
VictorKoenders Oct 12, 2021
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 .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"uses": "actions-rs/[email protected]",
"with": {
"version": "0.18.2",
"args": "--exclude-files derive/"
"args": "--all"
}
},
{
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.cargo
.vscode
rls*.log
tarpaulin-report.html
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
[package]
name = "bincode"
version = "2.0.0-dev" # remember to update html_root_url and bincode_derive
authors = ["Ty Overby <[email protected]>", "Francesco Mazzoli <[email protected]>", "Zoey Riordan <[email protected]>"]
authors = ["Ty Overby <[email protected]>", "Francesco Mazzoli <[email protected]>", "Zoey Riordan <[email protected]>", "Victor Koenders <[email protected]>"]
exclude = ["logo.png", "examples/*", ".gitignore", ".github/"]

publish = true
Expand All @@ -30,4 +30,9 @@ derive = ["bincode_derive"]

[dependencies]
bincode_derive = { path = "derive", version = "2.0.0-dev", optional = true }
# serde = { version = "1.0.130", optional = true }
serde = { version = "1.0.130", optional = true }

# Used for derive tests
[dev-dependencies]
serde_derive = "1.0.130"
serde_json = "1.0.68"
33 changes: 17 additions & 16 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[package]
name = "bincode_derive"
version = "2.0.0-dev" # remember to update bincode
edition = "2018"

[lib]
proc-macro = true

[dependencies]
quote = "1.0.9"
proc-macro2 = "1.0"

[dependencies.syn]
version = "1.0.74"
default-features = false
features = ["parsing", "derive", "proc-macro", "printing", "clone-impls"]
[package]
name = "bincode_derive"
version = "2.0.0-dev" # remember to update bincode
authors = ["Zoey Riordan <[email protected]>", "Victor Koenders <[email protected]>"]
edition = "2018"

repository = "https://github.com/bincode-org/bincode"
documentation = "https://docs.rs/bincode_derive"
readme = "./readme.md"
categories = ["encoding", "network-programming"]
keywords = ["binary", "encode", "decode", "serialize", "deserialize"]

[lib]
proc-macro = true

[dev-dependencies]
proc-macro2 = "1.0"
28 changes: 28 additions & 0 deletions derive/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Bincode-derive

The derive crate for bincode. Implements `bincode::Encodable` and `bincode::Decodable`.

This crate is roughly split into 2 parts:

# Parsing

Most of parsing is done in the `src/parse/` folder. This will generate the following types:
- `Attributes`, not being used currently
- `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 `src/derive_enum.rs` and `src/derive_struct.rs`.

This is supported by the structs in `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.

For additional derive testing, see the test cases in `../tests`

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.
Loading