Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bincode-org/bincode
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: bincode-org/bincode
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.1
Choose a head ref
  • 6 commits
  • 11 files changed
  • 3 contributors

Commits on Mar 6, 2025

  1. remove prerelease warning

    ZoeyR committed Mar 6, 2025
    Copy the full SHA
    e9de838 View commit details

Commits on Mar 10, 2025

  1. Update unty requirement from 0.0.3 to 0.0.4 (#753)

    Updates the requirements on [unty](https://github.com/bincode-org/unty) to permit the latest version.
    - [Commits](bincode-org/unty@v0.0.3...v0.0.4)
    
    ---
    updated-dependencies:
    - dependency-name: unty
      dependency-type: direct:production
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    dd3feea View commit details
  2. Use qualified path for Result::Ok in bincode_derive (#757)

    * Use qualified path for Result::Ok in bincode_derive
    
    * add test
    nhaef authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    bd99729 View commit details
  3. Fix issue when a foreign Err pollutes scope (#758)

    ZoeyR authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    89e4c40 View commit details
  4. Derive Debug for Configuration (#759)

    ZoeyR authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5500e5e View commit details
  5. bump version to 2.0.1 (#760)

    ZoeyR authored Mar 10, 2025
    Copy the full SHA
    4673360 View commit details
Showing with 57 additions and 37 deletions.
  1. +3 −3 Cargo.toml
  2. +1 −1 derive/Cargo.toml
  3. +4 −4 derive/src/derive_enum.rs
  4. +3 −3 derive/src/derive_struct.rs
  5. +11 −11 docs/migration_guide.md
  6. +7 −7 docs/spec.md
  7. +5 −5 fuzz/Cargo.lock
  8. +0 −1 readme.md
  9. +1 −1 src/config.rs
  10. +1 −1 src/lib.rs
  11. +21 −0 tests/derive.rs
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ members = ["derive", "compatibility"]

[package]
name = "bincode"
version = "2.0.0" # remember to update html_root_url and bincode_derive
version = "2.0.1" # remember to update html_root_url and bincode_derive
authors = [
"Ty Overby <ty@pre-alpha.com>",
"Zoey Riordan <zoey@dos.cafe>",
@@ -32,9 +32,9 @@ alloc = ["serde?/alloc"]
derive = ["bincode_derive"]

[dependencies]
bincode_derive = { path = "derive", version = "2.0.0", optional = true }
bincode_derive = { path = "derive", version = "2.0.1", optional = true }
serde = { version = "1.0", default-features = false, optional = true }
unty = "0.0.3"
unty = "0.0.4"

# Used for tests
[dev-dependencies]
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bincode_derive"
version = "2.0.0" # remember to update bincode
version = "2.0.1" # remember to update bincode
authors = [
"Zoey Riordan <zoey@dos.cafe>",
"Victor Koenders <bincode@trangar.com>",
8 changes: 4 additions & 4 deletions derive/src/derive_enum.rs
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ impl DeriveEnum {
}
}
}
body.push_parsed("Ok(())")?;
body.push_parsed("core::result::Result::Ok(())")?;
Ok(())
})?;
match_body.punct(',');
@@ -162,7 +162,7 @@ impl DeriveEnum {
// if we have fixed value variants
result.ident_str("variant");
result.puncts("=>");
result.ident_str("Err");
result.push_parsed("core::result::Result::Err")?;
result.group(Delimiter::Parenthesis, |err_inner| {
err_inner.push_parsed(format!(
"{}::error::DecodeError::UnexpectedVariant",
@@ -274,7 +274,7 @@ impl DeriveEnum {
variant_case.push(variant_index.remove(0));
}
variant_case.puncts("=>");
variant_case.ident_str("Ok");
variant_case.push_parsed("core::result::Result::Ok")?;
variant_case.group(Delimiter::Parenthesis, |variant_case_body| {
// Self::Variant { }
// Self::Variant { 0: ..., 1: ... 2: ... },
@@ -384,7 +384,7 @@ impl DeriveEnum {
variant_case.push(variant_index.remove(0));
}
variant_case.puncts("=>");
variant_case.ident_str("Ok");
variant_case.push_parsed("core::result::Result::Ok")?;
variant_case.group(Delimiter::Parenthesis, |variant_case_body| {
// Self::Variant { }
// Self::Variant { 0: ..., 1: ... 2: ... },
6 changes: 3 additions & 3 deletions derive/src/derive_struct.rs
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ impl DeriveStruct {
}
}
}
fn_body.push_parsed("Ok(())")?;
fn_body.push_parsed("core::result::Result::Ok(())")?;
Ok(())
})?;
Ok(())
@@ -95,7 +95,7 @@ impl DeriveStruct {
.with_return_type(format!("core::result::Result<Self, {}::error::DecodeError>", crate_name))
.body(|fn_body| {
// Ok(Self {
fn_body.ident_str("Ok");
fn_body.push_parsed("core::result::Result::Ok")?;
fn_body.group(Delimiter::Parenthesis, |ok_group| {
ok_group.ident_str("Self");
ok_group.group(Delimiter::Brace, |struct_body| {
@@ -174,7 +174,7 @@ impl DeriveStruct {
.with_return_type(format!("core::result::Result<Self, {}::error::DecodeError>", crate_name))
.body(|fn_body| {
// Ok(Self {
fn_body.ident_str("Ok");
fn_body.push_parsed("core::result::Result::Ok")?;
fn_body.group(Delimiter::Parenthesis, |ok_group| {
ok_group.ident_str("Self");
ok_group.group(Delimiter::Brace, |struct_body| {
22 changes: 11 additions & 11 deletions docs/migration_guide.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ Bincode 2 now has an optional dependency on `serde`. You can either use `serde`,

## From `Options` to `Configuration`

Bincode 1 had the [Options](https://docs.rs/bincode/1/bincode/config/trait.Options.html) trait. This has been replaced with the [Configuration](https://docs.rs/bincode/2.0.0/bincode/config/struct.Configuration.html) struct.
Bincode 1 had the [Options](https://docs.rs/bincode/1/bincode/config/trait.Options.html) trait. This has been replaced with the [Configuration](https://docs.rs/bincode/2/bincode/config/struct.Configuration.html) struct.

If you're using `Options`, you can change it like this:

@@ -46,10 +46,10 @@ If so, make sure to include bincode 2 with the `serde` feature enabled, and use

```toml
[dependencies]
bincode = { version = "2.0.0", features = ["serde"] }
bincode = { version = "2.0", features = ["serde"] }

# Optionally you can disable the `derive` feature:
# bincode = { version = "2.0.0", default-features = false, features = ["std", "serde"] }
# bincode = { version = "2.0", default-features = false, features = ["std", "serde"] }
```

Then replace the following functions: (`Configuration` is `bincode::config::legacy()` by default)
@@ -70,13 +70,13 @@ Then replace the following functions: (`Configuration` is `bincode::config::lega

```toml,ignore
[dependencies]
bincode = "2.0.0"
bincode = "2.0"
# If you need `no_std` with `alloc`:
# bincode = { version = "2.0.0", default-features = false, features = ["derive", "alloc"] }
# bincode = { version = "2.0", default-features = false, features = ["derive", "alloc"] }
# If you need `no_std` and no `alloc`:
# bincode = { version = "2.0.0", default-features = false, features = ["derive"] }
# bincode = { version = "2.0", default-features = false, features = ["derive"] }
```

Replace or add the following attributes. You are able to use both `serde-derive` and `bincode-derive` side-by-side.
@@ -86,7 +86,7 @@ Replace or add the following attributes. You are able to use both `serde-derive`
| `#[derive(serde::Serialize)]` | `#[derive(bincode::Encode)]` |
| `#[derive(serde::Deserialize)]` | `#[derive(bincode::Decode)]` |

**note:** To implement these traits manually, see the documentation of [Encode](https://docs.rs/bincode/2.0.0/bincode/enc/trait.Encode.html) and [Decode](https://docs.rs/bincode/2.0.0/bincode/de/trait.Decode.html).
**note:** To implement these traits manually, see the documentation of [Encode](https://docs.rs/bincode/2/bincode/enc/trait.Encode.html) and [Decode](https://docs.rs/bincode/2/bincode/de/trait.Decode.html).

**note:** For more information on using `bincode-derive` with external libraries, see [below](#bincode-derive-and-libraries).

@@ -107,10 +107,10 @@ Then replace the following functions: (`Configuration` is `bincode::config::lega
Currently not many libraries support the traits `Encode` and `Decode`. There are a couple of options if you want to use `#[derive(bincode::Encode, bincode::Decode)]`:

- Enable the `serde` feature and add a `#[bincode(with_serde)]` above each field that implements `serde::Serialize/Deserialize` but not `Encode/Decode`
- Enable the `serde` feature and wrap your field in [bincode::serde::Compat](https://docs.rs/bincode/2.0.0/bincode/serde/struct.Compat.html) or [bincode::serde::BorrowCompat](https://docs.rs/bincode/2.0.0/bincode/serde/struct.BorrowCompat.html)
- Enable the `serde` feature and wrap your field in [bincode::serde::Compat](https://docs.rs/bincode/2/bincode/serde/struct.Compat.html) or [bincode::serde::BorrowCompat](https://docs.rs/bincode/2/bincode/serde/struct.BorrowCompat.html)
- Make a pull request to the library:
- Make sure to be respectful, most of the developers are doing this in their free time.
- Add a dependency `bincode = { version = "2.0.0", default-features = false, optional = true }` to the `Cargo.toml`
- Implement [Encode](https://docs.rs/bincode/2.0.0/bincode/enc/trait.Encode.html)
- Implement [Decode](https://docs.rs/bincode/2.0.0/bincode/de/trait.Decode.html)
- Add a dependency `bincode = { version = "2.0", default-features = false, optional = true }` to the `Cargo.toml`
- Implement [Encode](https://docs.rs/bincode/2/bincode/enc/trait.Encode.html)
- Implement [Decode](https://docs.rs/bincode/2/bincode/de/trait.Decode.html)
- Make sure both of these implementations have a `#[cfg(feature = "bincode")]` attribute.
14 changes: 7 additions & 7 deletions docs/spec.md
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ By default, this serialization format uses little-endian byte order for basic nu

Endianness can be configured with the following methods, allowing for big-endian serialization when required:

- [`with_big_endian`](https://docs.rs/bincode/2.0.0/bincode/config/struct.Configuration.html#method.with_big_endian)
- [`with_little_endian`](https://docs.rs/bincode/2.0.0/bincode/config/struct.Configuration.html#method.with_little_endian)
- [`with_big_endian`](https://docs.rs/bincode/2/bincode/config/struct.Configuration.html#method.with_big_endian)
- [`with_little_endian`](https://docs.rs/bincode/2/bincode/config/struct.Configuration.html#method.with_little_endian)

### Byte Order Considerations

@@ -31,7 +31,7 @@ Endianness can be configured with the following methods, allowing for big-endian
- Encoded as a single byte
- `false` is represented by `0`
- `true` is represented by `1`
- During deserialization, values other than 0 and 1 will result in an error [`DecodeError::InvalidBooleanValue`](https://docs.rs/bincode/2.0.0/bincode/error/enum.DecodeError.html#variant.InvalidBooleanValue)
- During deserialization, values other than 0 and 1 will result in an error [`DecodeError::InvalidBooleanValue`](https://docs.rs/bincode/2/bincode/error/enum.DecodeError.html#variant.InvalidBooleanValue)

### Numeric Types

@@ -62,7 +62,7 @@ Endianness can be configured with the following methods, allowing for big-endian
- Surrogate code points (0xD800 to 0xDFFF) are not valid
- Invalid Unicode characters can be acquired via unsafe code, this is handled as:
- during serialization: data is written as-is
- during deserialization: an error is raised [`DecodeError::InvalidCharEncoding`](https://docs.rs/bincode/2.0.0/bincode/error/enum.DecodeError.html#variant.InvalidCharEncoding)
- during deserialization: an error is raised [`DecodeError::InvalidCharEncoding`](https://docs.rs/bincode/2/bincode/error/enum.DecodeError.html#variant.InvalidCharEncoding)
- No additional metadata or encoding scheme beyond the raw code point value

All tuples have no additional bytes, and are encoded in their specified order, e.g.
@@ -92,15 +92,15 @@ Encoding an unsigned integer v (of any type excepting u8/i8) works as follows:

`usize` is being encoded/decoded as a `u64` and `isize` is being encoded/decoded as a `i64`.

See the documentation of [VarintEncoding](https://docs.rs/bincode/2.0.0/bincode/config/struct.Configuration.html#method.with_variable_int_encoding) for more information.
See the documentation of [VarintEncoding](https://docs.rs/bincode/2/bincode/config/struct.Configuration.html#method.with_variable_int_encoding) for more information.

### FixintEncoding

- Fixed size integers are encoded directly
- Enum discriminants are encoded as u32
- Lengths and usize are encoded as u64

See the documentation of [FixintEncoding](https://docs.rs/bincode/2.0.0/bincode/config/struct.Configuration.html#method.with_fixed_int_encoding) for more information.
See the documentation of [FixintEncoding](https://docs.rs/bincode/2/bincode/config/struct.Configuration.html#method.with_fixed_int_encoding) for more information.

## Enums

@@ -224,7 +224,7 @@ assert_eq!(encoded.as_slice(), &[
- During serialization, the string is encoded as a sequence of the given bytes.
- Rust strings are UTF-8 encoded by default, but this is not enforced by bincode
- No normalization or transformation of text
- If an invalid UTF-8 sequence is encountered during decoding, an [`DecodeError::Utf8`](https://docs.rs/bincode/2.0.0/bincode/error/enum.DecodeError.html#variant.Utf8) error is raised
- If an invalid UTF-8 sequence is encountered during decoding, an [`DecodeError::Utf8`](https://docs.rs/bincode/2/bincode/error/enum.DecodeError.html#variant.Utf8) error is raised

```rust
let str = "Hello 🌍"; // Mixed ASCII and Unicode
10 changes: 5 additions & 5 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Bincode
### The following information is for the prerelease 2.x versions of this library. The stable branch can be found [here](https://github.com/bincode-org/bincode/tree/v1.x).
<img align="right" src="./logo.svg" />

[![CI](https://github.com/bincode-org/bincode/workflows/CI/badge.svg)](https://github.com/bincode-org/bincode/actions)
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ use core::marker::PhantomData;
/// [with_big_endian]: #method.with_big_endian
/// [with_fixed_int_encoding]: #method.with_fixed_int_encoding
/// [with_variable_int_encoding]: #method.with_variable_int_encoding
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct Configuration<E = LittleEndian, I = Varint, L = NoLimit> {
_e: PhantomData<E>,
_i: PhantomData<I>,
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@
//! [`net::TcpStream`]: std::net::TcpStream
//!
#![doc(html_root_url = "https://docs.rs/bincode/2.0.0")]
#![doc(html_root_url = "https://docs.rs/bincode/2.0.1")]
#![crate_name = "bincode"]
#![crate_type = "rlib"]

21 changes: 21 additions & 0 deletions tests/derive.rs
Original file line number Diff line number Diff line change
@@ -403,6 +403,27 @@ fn test_enum_with_generics_roundtrip() {
assert_eq!(start, decoded);
}

mod derive_with_polluted_scope {
#[allow(dead_code)]
#[allow(non_snake_case)]
fn Ok() {}

#[allow(dead_code)]
#[allow(non_snake_case)]
fn Err() {}

#[derive(bincode::Encode, bincode::Decode)]
struct A {
a: u32,
}

#[derive(bincode::Encode, bincode::Decode)]
enum B {
A,
B,
}
}

#[cfg(feature = "alloc")]
mod zoxide {
extern crate alloc;