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

Requires AsMut and AsRef with buffers > 32 bytes #29

Closed
ctron opened this issue Oct 2, 2020 · 2 comments
Closed

Requires AsMut and AsRef with buffers > 32 bytes #29

ctron opened this issue Oct 2, 2020 · 2 comments

Comments

@ctron
Copy link

ctron commented Oct 2, 2020

I think this is similar to the issue #21:

Assume the following code:

extern crate bitfield;
use bitfield::bitfield;

pub const SIZE: usize = 33;

bitfield! {
    pub struct Foo(MSB0[u8]);
    impl Debug;

    pub u8, foo, _ : 0;
}

fn main() {
    let buffer = [0u8; SIZE];
    Foo(buffer).foo();
}

This will result in:

error[E0599]: no method named `foo` found for struct `Foo<[u8; 33]>` in the current scope
  --> src/main.rs:16:17
   |
7  | / bitfield! {
8  | |     pub struct Foo(MSB0[u8]);
9  | |     impl Debug;
10 | |
11 | |     pub u8, foo, _ : 0;
12 | | }
   | |_- method `foo` not found for this
...
16 |       Foo(buffer).foo();
   |                   ^^^ method not found in `Foo<[u8; 33]>`
   |
   = note: the method `foo` exists but the following trait bounds were not satisfied:
           `[u8; 33]: std::convert::AsRef<[u8]>`
           `[u8; 33]: std::convert::AsMut<[u8]>`

If you lower the size to "32" (or less), it works.

@ctron
Copy link
Author

ctron commented Oct 2, 2020

You can work around this using the following code:

let mut foo = Foo(buffer);
let foo = Foo(&mut foo.0[..]);
foo.foo();

But this requires to have a mut instance, even for "read-only" operations.

@dzamlo
Copy link
Owner

dzamlo commented Oct 2, 2020

Like #28, this is fixed in the beta toolchain.

But this requires to have a mut instance, even for "read-only" operations.

This part of the issue is the same as #23

@dzamlo dzamlo closed this as completed Oct 2, 2020
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

No branches or pull requests

2 participants