Skip to content

Commit

Permalink
Merge pull request #41 from serpilliere/add_get_parent
Browse files Browse the repository at this point in the history
Add get_parent
  • Loading branch information
a1ien authored Oct 16, 2020
2 parents 59d9ac6 + a6f85c4 commit e8863f0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,18 @@ impl<T: UsbContext> Device<T> {
pub fn port_number(&self) -> u8 {
unsafe { libusb_get_port_number(self.device.as_ptr()) }
}

/// Returns the device's parent
pub fn get_parent(&self) -> Option<Self> {
let device = unsafe { libusb_get_parent(self.device.as_ptr()) };
NonNull::new(device)
.map(|device|
unsafe {
Device::from_libusb(
self.context.clone(),
device,
)
}
)
}
}

0 comments on commit e8863f0

Please sign in to comment.