You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
This is Rust's limitation (rust-lang/rust#44580) which I can't solve in this crate alone 😄. You could turn the &[u8; N] into &[u8] through this though:
let code = QrCode::new(&b"this string has length 50 which is greater than 32"[..]).unwrap();// ^ ^^^^
If we attempt to encode a string with
string.len()
greater than 32, we get an error.Modified example
Here is the error
As it seems from
std::convert::AsRef
, the traitAsRef
is only implemented for arrays <= 32 elements but in this case the string gets converted to byte array which happens to be > 32 elements.The text was updated successfully, but these errors were encountered: