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

Arc<str> can't be bincoded #527

Closed
nalply opened this issue Mar 22, 2022 · 2 comments · Fixed by #526
Closed

Arc<str> can't be bincoded #527

nalply opened this issue Mar 22, 2022 · 2 comments · Fixed by #526

Comments

@nalply
Copy link

nalply commented Mar 22, 2022

Arc<str> can't be bincoded with bincode 2. See code and error message below. Arc<&str> works though. Link to gist at bottom.

use std::sync::Arc;
use bincode;

fn main() {
  let val: Arc<str> = std::sync::Arc::from("Example String");
  let config = bincode::config::standard();
  let encoded = bincode::encode_to_vec(val, config).unwrap();


  for byte in encoded {
    print!(" {byte:02x}");
  }
  println!();
}

compiled on rustc 1.61.0-nightly (58f11791a 2022-03-17) on MacOS gives:

error[E0277]: the size for values of type `str` cannot be known at compilation time
  --> minimal_example/src/main.rs:7:40
   |
7  |   let encoded = bincode::encode_to_vec(val, config).unwrap();
   |                 ---------------------- ^^^ doesn't have a size known at compile-time
   |                 |
   |                 required by a bound introduced by this call
   |
   = help: the trait `Sized` is not implemented for `str`
   = note: required because of the requirements on the impl of `Encode` for `Arc<str>`
note: required by a bound in `encode_to_vec`
  --> /Users/nalp/.cargo/registry/src/github.ghproxy.top-1ecc6299db9ec823/bincode-2.0.0-rc.1/src/features/impl_alloc.rs:42:25
   |
42 | pub fn encode_to_vec<E: enc::Encode, C: Config>(val: E, config: C) -> Result<Vec<u8>, EncodeError> {
   |                         ^^^^^^^^^^^ required by this bound in `encode_to_vec`

https://gist.github.com/nalply/c29385f0046ca03ae0f3a687dfeb24d1

@VictorKoenders
Copy link
Contributor

This is part of a larger issue where we might have to split Decode and BorrowDecode into separate traits. Work is being done in #526 but it's going to be a slow process.

@VictorKoenders
Copy link
Contributor

VictorKoenders commented Apr 8, 2022

We can implement Encode for Arc<str>, however we cannot implement Decode for Arc<str> as this would conflict with Decode for Arc<T>.

Edit: I'm wrong and it should all work in 2.0.0-rc.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants