Rust library cleanup

* Fix error code extraction from Python to Rust
* Add documentation for dealing with HCI packets
This commit is contained in:
Gabriel White-Vega
2023-10-11 10:32:33 -04:00
parent dedc0aca54
commit ae23ef7b9b
4 changed files with 93 additions and 3 deletions

View File

@@ -178,7 +178,11 @@ impl IntoPy<PyObject> for AddressType {
impl<'source> FromPyObject<'source> for ErrorCode {
fn extract(ob: &'source PyAny) -> PyResult<Self> {
ob.extract()
// Bumble represents error codes simply as a single-byte number (in Rust, u8)
let value: u8 = ob.extract()?;
ErrorCode::try_from(value).map_err(|b| {
PyErr::new::<PyException, _>(format!("Failed to map {b} to an error code"))
})
}
}