Closed
Description
If we attempt to encode a string with string.len()
greater than 32, we get an error.
Modified example
extern crate qrcode;
extern crate image;
use qrcode::QrCode;
use image::Luma;
fn main() {
// Encode some data into bits.
let code = QrCode::new(b"this string has length 50 which is greater than 32").unwrap();
// Render the bits into an image.
let image = code.render::<Luma<u8>>().build();
// Save the image.
image.save("/tmp/qrcode.png").unwrap();
}
Here is the error
error[E0277]: the trait bound `[u8; 50]: std::convert::AsRef<[u8]>` is not satisfied
--> src/main.rs:9:16
|
9 | let code = QrCode::new(b"this string has length 50 which is greater than 32").unwrap();
| ^^^^^^^^^^^ the trait `std::convert::AsRef<[u8]>` is not implemented for `[u8; 50]`
|
= help: the following implementations were found:
<[T; <unevaluated[]>] as std::convert::AsRef<[T]>>
<[T; <unevaluated[]>] as std::convert::AsRef<[T]>>
<[T; <unevaluated[]>] as std::convert::AsRef<[T]>>
<[T; <unevaluated[]>] as std::convert::AsRef<[T]>>
and 30 others
= note: required because of the requirements on the impl of `std::convert::AsRef<[u8]>` for `&[u8; 50]`
= note: required by `qrcode::QrCode::new`
As it seems from std::convert::AsRef
, the trait AsRef
is only implemented for arrays <= 32 elements but in this case the string gets converted to byte array which happens to be > 32 elements.
Metadata
Metadata
Assignees
Labels
No labels