| Crates.io | yuca |
| lib.rs | yuca |
| version | 0.1.0 |
| created_at | 2024-12-19 02:16:19.01051+00 |
| updated_at | 2024-12-19 02:16:19.01051+00 |
| description | Access USB Type-C device information on Linux |
| homepage | |
| repository | https://github.com/collabora/yuca |
| max_upload_size | |
| id | 1488697 |
| size | 151,334 |
Yuca is a Rust crate to access USB Type-C device information on Linux.
use std::error::Error;
use futures_lite::StreamExt;
use yuca::{sysfs::*, watcher::*};
fn show() -> Result<(), Box<dyn Error>> {
for port in Port::collection()?.list()? {
let port = port.open()?;
println!("Port: {}", port.path().port);
let Ok(partner) = port.partner().open() else { continue; };
println!(" Partner: {}:{}",
partner.identity().id_header().get()?.0.vendor_id(),
partner.identity().product().get()?.product_id);
}
Ok(())
}
async fn watch() -> Result<(), Box<dyn Error>> {
let (w, _) = Watcher::spawn_tokio(EventSource::Netlink)?;
let mut stream = PartnerPath::any_added(&w)?;
while let Some(path) = stream.next().await {
let Ok(path) = path else { continue; };
println!("Partner added to port: {}", path.port);
}
Ok(())
}
This crate uses a variety of terms from the USB Power Delivery specification, which can be obtained from here. Consult the spec's "Terms and Abbreviations" for complete definitions.