Open stevenroose opened 5 years ago
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?
Use rusb, which is a fork of this library that uses reference counting for its Context
type, and is more actively maintained.
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 theContext
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 theHandle
type does not have a lifetime defined, but just documents that it cannot outlive theHidManager
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 theContext
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.