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

Cannot use iter_mut() on mutable CxxVector? #625

Closed
NiceneNerd opened this issue Dec 31, 2020 · 2 comments
Closed

Cannot use iter_mut() on mutable CxxVector? #625

NiceneNerd opened this issue Dec 31, 2020 · 2 comments

Comments

@NiceneNerd
Copy link

As far as I can tell, if you acquire a mutable vector from C++ as Pin<&mut CxxVector<T>>, it's counterintuitively not possible to use iter_mut() with it. For example, in my bridge:

fn GetArray(self: Pin<&mut Byml>) -> Pin<&mut CxxVector<Byml>>;

The result when I try to iterate using byml.GetArray().iter_mut():

error[E0596]: cannot borrow data in a dereference of `Pin<&mut CxxVector<ffi::Byml>>` as mutable
  --> src/byml/mod.rs:55:17
   |
55 |                 byml.GetArray()
   |                 ^^^^^^^^^^^^^^^ cannot borrow as mutable
   |
   = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<&mut CxxVector<ffi::Byml>>````

Just to check, I also found it happens with more trivial cases like `Pin<&mut CxxVector<u8>>`.
@NiceneNerd NiceneNerd changed the title Cannot use iter_mut on mutable CxxVector? Cannot use iter_mut() on mutable CxxVector? Dec 31, 2020
@dtolnay
Copy link
Owner

dtolnay commented Dec 31, 2020

Good catch, that method was accidentally uncallable. I published 1.0.25 with a fix to make it work on Pin<&mut CxxVector>.

@NiceneNerd
Copy link
Author

Awesome, thanks for the quick fix

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