Skip to content

Commit 484a9ce

Browse files
Make bincode_derive 0 dependencies (bincode-org#409)
Removed `syn`, `quote` and `proc_macro2` dependency
1 parent cb23078 commit 484a9ce

25 files changed

+2172
-518
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
"uses": "actions-rs/[email protected]",
163163
"with": {
164164
"version": "0.18.2",
165-
"args": "--exclude-files derive/"
165+
"args": "--all"
166166
}
167167
},
168168
{

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
.cargo
66
.vscode
77
rls*.log
8+
tarpaulin-report.html

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
[package]
77
name = "bincode"
88
version = "2.0.0-dev" # remember to update html_root_url and bincode_derive
9-
authors = ["Ty Overby <[email protected]>", "Francesco Mazzoli <[email protected]>", "Zoey Riordan <[email protected]>"]
9+
authors = ["Ty Overby <[email protected]>", "Francesco Mazzoli <[email protected]>", "Zoey Riordan <[email protected]>", "Victor Koenders <[email protected]>"]
1010
exclude = ["logo.png", "examples/*", ".gitignore", ".github/"]
1111

1212
publish = true
@@ -30,4 +30,9 @@ derive = ["bincode_derive"]
3030

3131
[dependencies]
3232
bincode_derive = { path = "derive", version = "2.0.0-dev", optional = true }
33-
# serde = { version = "1.0.130", optional = true }
33+
serde = { version = "1.0.130", optional = true }
34+
35+
# Used for derive tests
36+
[dev-dependencies]
37+
serde_derive = "1.0.130"
38+
serde_json = "1.0.68"

derive/Cargo.toml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
[package]
2-
name = "bincode_derive"
3-
version = "2.0.0-dev" # remember to update bincode
4-
edition = "2018"
5-
6-
[lib]
7-
proc-macro = true
8-
9-
[dependencies]
10-
quote = "1.0.9"
11-
proc-macro2 = "1.0"
12-
13-
[dependencies.syn]
14-
version = "1.0.74"
15-
default-features = false
16-
features = ["parsing", "derive", "proc-macro", "printing", "clone-impls"]
1+
[package]
2+
name = "bincode_derive"
3+
version = "2.0.0-dev" # remember to update bincode
4+
authors = ["Zoey Riordan <[email protected]>", "Victor Koenders <[email protected]>"]
5+
edition = "2018"
6+
7+
repository = "https://github.com/bincode-org/bincode"
8+
documentation = "https://docs.rs/bincode_derive"
9+
readme = "./readme.md"
10+
categories = ["encoding", "network-programming"]
11+
keywords = ["binary", "encode", "decode", "serialize", "deserialize"]
12+
13+
[lib]
14+
proc-macro = true
15+
16+
[dev-dependencies]
17+
proc-macro2 = "1.0"

derive/readme.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Bincode-derive
2+
3+
The derive crate for bincode. Implements `bincode::Encodable` and `bincode::Decodable`.
4+
5+
This crate is roughly split into 2 parts:
6+
7+
# Parsing
8+
9+
Most of parsing is done in the `src/parse/` folder. This will generate the following types:
10+
- `Attributes`, not being used currently
11+
- `Visibility`, not being used currently
12+
- `DataType` either `Struct` or `Enum`, with the name of the data type being parsed
13+
- `Generics` the generics part of the type, e.g. `struct Foo<'a>`
14+
- `GenericConstraints` the "where" part of the type
15+
16+
# Generate
17+
18+
Generating the code implementation is done in either `src/derive_enum.rs` and `src/derive_struct.rs`.
19+
20+
This is supported by the structs in `src/generate`. The most notable points of this module are:
21+
- `StreamBuilder` is a thin but friendly wrapper around `TokenStream`
22+
- `Generator` is the base type of the code generator. This has helper methods to generate implementations:
23+
- `ImplFor` is a helper struct for a single `impl A for B` construction. In this functions can be defined:
24+
- `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.
25+
26+
For additional derive testing, see the test cases in `../tests`
27+
28+
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.

0 commit comments

Comments
 (0)