Skip to content

Commit aa7a351

Browse files
committed
replace bincode with postcard, upgrade syn 1->2
1 parent 570a64e commit aa7a351

33 files changed

Lines changed: 46 additions & 59 deletions

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ build = "build.rs"
1212

1313
[features]
1414
derive = ["cumulo-dipa-derive"]
15-
impl-tester = ["bincode"]
15+
impl-tester = ["postcard"]
1616

1717
[dependencies]
18-
bincode = {optional = true, version = "1.3"}
18+
postcard = {optional = true, version = "1", features = ["use-std"]}
1919
serde = {version = "1", features = ["derive"]}
2020

2121
# Optional Dependencies
2222
cumulo-dipa-derive = {optional = true, version = "0.1", path = "./crates/dipa-derive", package = "cumulo-dipa-derive"}
2323

2424
[dev-dependencies]
25-
bincode = "1.3"
25+
postcard = {version = "1", features = ["use-std"]}
2626

2727
[workspace]
2828
members = [

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ bincode = "1"
6161
dipa = { version = "0.1", features = ["derive"] }
6262
serde = { version = "1", features = ["derive"] }
6363
```
64+
6465
</details>
6566
<p></p>
6667

@@ -120,7 +121,7 @@ fn main() {
120121

121122
// ... Pretend you send the data to the client ...
122123

123-
let deserialized: <MyClientState as dipa::Diffable<'_, '_, MyClientState>>::DeltaOwned =
124+
let deserialized: <MyClientState as dipa::Diffable<'_, '_, MyClientState>>::DeltaOwned =
124125
bin.deserialize(&serialized).unwrap();
125126

126127
old_client_state.apply_patch(deserialized);
@@ -137,7 +138,7 @@ fn main() {
137138

138139
## Advanced Usage
139140

140-
For applications where incredibly small payloads are a top priority, you may wish to take advantage of knowledge about how your application works in order to
141+
For applications where incredibly small payloads are a top priority, you may wish to take advantage of knowledge about how your application works in order to
141142
generate even smaller diffs.
142143

143144
For example, say you have the following client state data structure.

crates/dipa-derive/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ proc-macro = true
1414
[dependencies]
1515
# extra-traits used to #[derive(Debug)] on syn::Lit. Can be removed after we're doing iterating on
1616
# getting things working.
17-
syn = {version = "1.0", features = ["extra-traits"] }
17+
syn = {version = "2.0", features = ["extra-traits"] }
1818
quote = "1.0"
19+
proc-macro2 = "1.0"
1920

crates/dipa-derive/src/dipa_attribute.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod max_fields_per_batch;
1212
pub fn maybe_parse_raw_dipa_attribute(attrs: Vec<Attribute>) -> Option<Attribute> {
1313
attrs
1414
.into_iter()
15-
.find(|a| a.path.segments.last().unwrap().ident.to_string().as_str() == "dipa")
15+
.find(|a| a.path().segments.last().unwrap().ident.to_string().as_str() == "dipa")
1616
}
1717

1818
/// A parsed representation of the #[dipa(...)] container attribute.
@@ -32,12 +32,9 @@ impl Parse for DipaAttrs {
3232
return Ok(dipa_attrs);
3333
}
3434

35-
let content;
36-
parenthesized!(content in input);
37-
3835
let opts =
3936
syn::punctuated::Punctuated::<DipaContainerAttr, syn::token::Comma>::parse_terminated(
40-
&content,
37+
input,
4138
)?;
4239

4340
for dipa_attr in opts.into_iter() {

crates/dipa-derive/src/dipa_attribute/field_batching_strategy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::dipa_attribute::DipaContainerAttr;
22
use crate::{SynError, SynResult};
3-
use quote::__private::Span;
3+
use proc_macro2::Span;
44
use std::str::FromStr;
55
use syn::parse::ParseBuffer;
66
use syn::LitStr;
7-
use syn::__private::TokenStream2;
7+
use proc_macro2::TokenStream as TokenStream2;
88
use syn::spanned::Spanned;
99

1010
/// The strategy used to encode the delta of a struct or enum variant that has 2 or more fields.

crates/dipa-derive/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::single_variant_enum::{
1313
use crate::zst_impl::create_zst_impl;
1414
use proc_macro::TokenStream;
1515
use quote::quote;
16-
use syn::__private::TokenStream2;
16+
use proc_macro2::TokenStream as TokenStream2;
1717
use syn::spanned::Spanned;
1818
use syn::{parse_macro_input, Data, DeriveInput, Fields};
1919
use syn::{Error as SynError, Result as SynResult};
@@ -46,11 +46,10 @@ pub fn derive_diff_patch(input: TokenStream) -> TokenStream {
4646
let input = parse_macro_input!(input as DeriveInput);
4747

4848
let dipa_attrs = match maybe_parse_raw_dipa_attribute(input.attrs) {
49-
Some(attrib) => {
50-
let attrib_tokens = attrib.tokens.into();
51-
52-
Some(parse_macro_input!(attrib_tokens as DipaAttrs))
53-
}
49+
Some(attrib) => match attrib.parse_args::<DipaAttrs>() {
50+
Ok(attrs) => Some(attrs),
51+
Err(e) => return e.into_compile_error().into(),
52+
},
5453
None => None,
5554
}
5655
.unwrap_or(DipaAttrs::default());

crates/dipa-derive/src/multi_field_utils/field_changes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syn::Ident;
55

66
mod all_combinations;
77
pub(crate) use self::all_combinations::make_bool_combinations;
8-
use syn::__private::TokenStream2;
8+
use proc_macro2::TokenStream as TokenStream2;
99

1010
/// All of the field indices that have changed within a struct/tuple.
1111
///

crates/dipa-derive/src/multi_field_utils/struct_or_tuple_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use quote::__private::Span;
22
use std::ops::{Deref, DerefMut};
3-
use syn::__private::TokenStream2;
3+
use proc_macro2::TokenStream as TokenStream2;
44
use syn::spanned::Spanned;
55
use syn::{Ident, Type};
66

crates/dipa-derive/src/multi_field_utils/struct_or_tuple_field/generate_delta_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::dipa_attribute::{DipaAttrs, FieldBatchingStrategy};
22
use crate::multi_field_utils::ParsedFields;
33
use syn::Ident;
4-
use syn::__private::TokenStream2;
4+
use proc_macro2::TokenStream as TokenStream2;
55

66
mod no_batching;
77
mod one_batch;

crates/dipa-derive/src/multi_field_utils/struct_or_tuple_field/generate_delta_type/no_batching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::dipa_attribute::DipaAttrs;
22
use crate::multi_field_utils::ParsedFields;
3-
use syn::__private::TokenStream2;
3+
use proc_macro2::TokenStream as TokenStream2;
44

55
impl ParsedFields {
66
pub(super) fn generate_delta_type_no_batching(

0 commit comments

Comments
 (0)