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

Add seriailize and deserialize usize #9

Merged
merged 6 commits into from
Jan 25, 2021
Merged

Add seriailize and deserialize usize #9

merged 6 commits into from
Jan 25, 2021

Conversation

ailisp
Copy link
Member

@ailisp ailisp commented Jan 25, 2021

As @olonho and other libs (serde, bincode, etc.) point out, this is not a hack, it serialize usize as if it were u64. It deserialize usize as if it were u64, and convert to usize. When overflow on deserialize, it return error

@ailisp
Copy link
Member Author

ailisp commented Jan 25, 2021

Hmm run these pass locally:

  • cargo fmt --all -- --check
  • cargo build --verbose
  • cargo test --verbose
  • cd borsh && cargo test --verbose --no-default-features

And fail on ci doesn't seem to revelant to the change (no usize in the enum), any ideas?
10:34

failures:---- enum_schema::tests::complex_enum_generics stdout ----thread 'enum_schema::tests::complex_enum_generics' panicked at 'assertion failed: `(left == right)`  left: `"impl < C , W > borsh :: BorshSchema for A < C , W > where C : borsh :: BorshSchema , W : borsh :: BorshSchema { fn declaration () -> borsh :: schema :: Declaration { let params = borsh :: maybestd :: vec ! [< C > :: declaration () , < W > :: declaration ()] ; format ! (r#\"{}<{}>\"# , \"A\" , params . join (\", \")) } fn add_definitions_recursively (definitions : & mut borsh :: maybestd :: collections :: HashMap < borsh :: schema :: Declaration , borsh :: schema :: Definition >) { # [derive (borsh :: BorshSchema)] struct ABacon < C , W > (# [borsh_skip] :: core :: marker :: PhantomData < (C , W) >) ; # [derive (borsh :: BorshSchema)] struct AEggs < C , W > (# [borsh_skip] :: core :: marker :: PhantomData < (C , W) >) ; # [derive (borsh :: BorshSchema)] struct ASalad < C , W > (Tomatoes , C , Oil , # [borsh_skip] :: core :: marker :: PhantomData < (C , W) >) ; # [derive (borsh :: BorshSchema)] struct ASausage < C , W > { wrapper : W , filling : Filling , # [borsh_skip] borsh_schema_phantom_data : :: core :: marker :: PhantomData < (C , W) > } < ABacon < C , W > > :: add_definitions_recursively (definitions) ; < AEggs < C , W > > :: add_definitions_recursively (definitions) ; < ASalad < C , W > > :: add_definitions_recursively (definitions) ; < ASausage < C , W > > :: add_definitions_recursively (definitions) ; let variants = borsh :: maybestd :: vec ! [(\"Bacon\" . to_string () , < ABacon < C , W > > :: declaration ()) , (\"Eggs\" . to_string () , < AEggs < C , W > > :: declaration ()) , (\"Salad\" . to_string () , < ASalad < C , W > > :: declaration ()) , (\"Sausage\" . to_string () , < ASausage < C , W > > :: declaration ())] ; let definition = borsh :: schema :: Definition :: Enum { variants } ; Self :: add_definition (Self :: declaration () , definition , definitions) ; } }"`, right: `"impl < C , W > borsh :: BorshSchema for A < C , W > where C : borsh :: BorshSchema , W : borsh :: BorshSchema { fn declaration () -> borsh :: schema :: Declaration { let params = borsh :: maybestd :: vec ! [< C > :: declaration () , < W > :: declaration ()] ; format ! (r#\"{}<{}>\"# , \"A\" , params . join (\", \")) } fn add_definitions_recursively (definitions : & mut borsh :: maybestd :: collections :: HashMap < borsh :: schema :: Declaration , borsh :: schema :: Definition >) { # [derive (borsh :: BorshSchema)] struct ABacon < C , W > (# [borsh_skip] :: core :: marker :: PhantomData < (C , W ,) >) ; # [derive (borsh :: BorshSchema)] struct AEggs < C , W > (# [borsh_skip] :: core :: marker :: PhantomData < (C , W ,) >) ; # [derive (borsh :: BorshSchema)] struct ASalad < C , W > (Tomatoes , C , Oil , # [borsh_skip] :: core :: marker :: PhantomData < (C , W ,) >) ; # [derive (borsh :: BorshSchema)] struct ASausage < C , W > { wrapper : W , filling : Filling , # [borsh_skip] borsh_schema_phantom_data : :: core :: marker :: PhantomData < (C , W ,) > } < ABacon < C , W > > :: add_definitions_recursively (definitions) ; < AEggs < C , W > > :: add_definitions_recursively (definitions) ; < ASalad < C , W > > :: add_definitions_recursively (definitions) ; < ASausage < C , W > > :: add_definitions_recursively (definitions) ; let variants = borsh :: maybestd :: vec ! [(\"Bacon\" . to_string () , < ABacon < C , W > > :: declaration ()) , (\"Eggs\" . to_string () , < AEggs < C , W > > :: declaration ()) , (\"Salad\" . to_string () , < ASalad < C , W > > :: declaration ()) , (\"Sausage\" . to_string () , < ASausage < C , W > > :: declaration ())] ; let definition = borsh :: schema :: Definition :: Enum { variants } ; Self :: add_definition (Self :: declaration () , definition , definitions) ; } }"`', borsh-schema-derive-internal/src/enum_schema.rs:138:9note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

borsh/src/de/mod.rs Outdated Show resolved Hide resolved
Copy link

@olonho olonho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, maybe better wording in error message.

Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sold on adding support for usize since someone can shoot themselves in the foot, but if you think it makes sense, I am fine with that.

@ailisp ailisp merged commit c62cdfb into master Jan 25, 2021
@ailisp ailisp deleted the usize-hack branch January 25, 2021 23:18
This was referenced May 31, 2023
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