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

Unable to store, or Box, a DeviceHandle. #32

Open
stevenroose opened this issue May 20, 2019 · 2 comments
Open

Unable to store, or Box, a DeviceHandle. #32

stevenroose opened this issue May 20, 2019 · 2 comments

Comments

@stevenroose
Copy link

stevenroose commented May 20, 2019

I can't find a way to hold a DeviceHandle in a struct and pass it around. It has a lifetime that must be longer than the Context object that created it. However, even when Boxing the Context and the DeviceHandle together, it's impossible to store a handle.

Did anyone get this to work? I need to store the handle because of how I have a transport-agnostic library built. It also uses the hid crate where the Handle type does not have a lifetime defined, but just documents that it cannot outlive the HidManager type. So I can just manually drop the Handle before dropping the manager.

@dcuddeback I saw a comment where you assume all users will create the Context in main and then just keep it around. Well, I'm not an end user, but a library implementer. The library connects to devices that support with WebUSB, HID and an HTTP bridge daemon. So the Context is created inside the library code and it's impossible to create the context and have it outlive the interface client object that the library returns.

@gdelazzari
Copy link

I'm having the same issue, I need to return a struct from a function with a DeviceHandle inside. I'm fine with making the struct also hold another Context, specifically created for the struct instance, but I can't find a way to tell the borrow checker that what I'm trying to do is fine.

Did you happen to find a way without resorting to unsafe?

@kevinmehall
Copy link
Contributor

Use rusb, which is a fork of this library that uses reference counting for its Context type, and is more actively maintained.

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

3 participants