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

Fix building with Rust 1.34 and add a GitHub workflow for checking this property #21

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

psychon
Copy link
Contributor

@psychon psychon commented Aug 10, 2024

Hi,

thanks for your input in #20. Turns out I already broke the MSRV that you figured out. Here's a fix for that and a workflow to keep this working.

Edit: I want to highlight that only tests do not compile with 1.34. The library itself is fine.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Cursor only implements Read if its inner type implements AsRef<[u8]>.
in Rust 1.34, this is not the case for arrays with 128 entries, which
FILE_CONTENTS is. Thus, we have to explicitly turn this into a slice

Compiler error:

    error[E0277]: the trait bound `[u8; 128]: std::convert::AsRef<[u8]>` is not satisfied
       --> src/parser.rs:225:20
        |
    225 |         assert_eq!(parse_header(&mut cursor).unwrap(), (16, 1));
        |                    ^^^^^^^^^^^^ the trait `std::convert::AsRef<[u8]>` is not implemented for `[u8; 128]`
        |
        = help: the following implementations were found:
                  <[T; 0] as std::convert::AsRef<[T]>>
                  <[T; 10] as std::convert::AsRef<[T]>>
                  <[T; 11] as std::convert::AsRef<[T]>>
                  <[T; 12] as std::convert::AsRef<[T]>>
                and 30 others
        = note: required because of the requirements on the impl of `std::convert::AsRef<[u8]>` for `&[u8; 128]`
        = note: required because of the requirements on the impl of `std::io::Read` for `std::io::Cursor<&[u8; 128]>`
    note: required by `parser::parse_header`
       --> src/parser.rs:58:1
        |
    58  | fn parse_header(i: &mut impl Read) -> IoResult<(u32, u32)> {
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Uli Schlachter <psychon@znc.in>
@MaxVerevkin
Copy link
Contributor

MaxVerevkin commented Aug 11, 2024

Maybe we should not lock the msrv on 1.34? I noticed that the parsing code could avoid a couple of allocations by using const generics, but that would require 1.51 (which is still more than 3 years old!)

Edit: nevermind all tags are 4 bytes :)

@esposm03 esposm03 merged commit 11741ea into esposm03:master Aug 12, 2024
2 checks passed
@psychon psychon deleted the msrv-check branch August 12, 2024 15:18
@psychon
Copy link
Contributor Author

psychon commented Aug 12, 2024

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants