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

empty byte returns byte array of zero #277

Closed
imerkle opened this issue Aug 25, 2019 · 1 comment
Closed

empty byte returns byte array of zero #277

imerkle opened this issue Aug 25, 2019 · 1 comment

Comments

@imerkle
Copy link

@imerkle imerkle commented Aug 25, 2019

        let y: &[u8] = &[];

        println!("{:?}", bincode::serialize(b"").unwrap()); //[]
        println!("{:?}", bincode::serialize(y).unwrap()); //[0,0,0,0,0,0,0,0]

      assert_eq!(bincode::serialize(b"").unwrap(), bincode::serialize(y).unwrap()); //false
@nox
Copy link
Member

@nox nox commented Aug 25, 2019

b"" is a &[u8; 0] whose size is statically known and thus doesn't need to be serialised, whereas y is a &[u8] which serialises to just its length 0. This behaviour is expected.

@imerkle imerkle closed this Aug 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.