Created
March 22, 2022 19:23
-
-
Save nalply/c29385f0046ca03ae0f3a687dfeb24d1 to your computer and use it in GitHub Desktop.
Minimal example for `Arc<str>` bincode fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "minimal_example" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
bincode = "2.0.0-rc.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(); | |
} | |
// Error message: | |
// 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.com-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` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment