aboutsummaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorGabriel White-Vega <gwhitevega@google.com>2023-10-02 11:20:44 -0400
committerGabriel White-Vega <gwhitevega@google.com>2023-10-02 11:20:44 -0400
commitce746904200d7aa7e8680317c0150ddb42704905 (patch)
tree41bfd831fdbe5c98ef3c3222e595ab81bf197a08 /rust
parent511ab4b6300cea671832eee5df712804962e1c17 (diff)
downloadbumble-ce746904200d7aa7e8680317c0150ddb42704905.tar.gz
Update pdl to 0.2.0
- Allows removing impl PartialEq for pdl Error
Diffstat (limited to 'rust')
-rw-r--r--rust/Cargo.lock19
-rw-r--r--rust/Cargo.toml3
-rw-r--r--rust/pytests/wrapper.rs10
-rw-r--r--rust/src/internal/hci/mod.rs85
-rw-r--r--rust/src/internal/hci/tests.rs8
-rw-r--r--rust/src/wrapper/hci.rs2
6 files changed, 33 insertions, 94 deletions
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 5858eb2..c443561 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -200,6 +200,7 @@ dependencies = [
"nom",
"owo-colors",
"pdl-derive",
+ "pdl-runtime",
"pyo3",
"pyo3-asyncio",
"rand",
@@ -1157,9 +1158,9 @@ dependencies = [
[[package]]
name = "pdl-compiler"
-version = "0.1.7"
+version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f99a9ac3d6a426c6fc0b85903a16d77bf148e20ddf755361f76e230d1b6d72cf"
+checksum = "ee66995739fb9ddd9155767990a54aadd226ee32408a94f99f94883ff445ceba"
dependencies = [
"argh",
"codespan-reporting",
@@ -1176,9 +1177,9 @@ dependencies = [
[[package]]
name = "pdl-derive"
-version = "0.1.7"
+version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ad882bdd3b2584b42180b7a216bfccc7c05e714de2789ee25ea622c85064ef7"
+checksum = "113e4a1215c407466b36d2c2f6a6318819d6b22ccdd3acb7bb35e27a68806034"
dependencies = [
"codespan-reporting",
"pdl-compiler",
@@ -1189,6 +1190,16 @@ dependencies = [
]
[[package]]
+name = "pdl-runtime"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2d36c2f9799613babe78eb5cd9a353d527daaba6c3d1f39a1175657a35790732"
+dependencies = [
+ "bytes",
+ "thiserror",
+]
+
+[[package]]
name = "percent-encoding"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 205898b..35a0f4c 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -24,7 +24,8 @@ itertools = "0.11.0"
lazy_static = "1.4.0"
thiserror = "1.0.41"
bytes = "1.5.0"
-pdl-derive = "0.1.7"
+pdl-derive = "0.2.0"
+pdl-runtime = "0.2.0"
# Dev tools
file-header = { version = "0.1.2", optional = true }
diff --git a/rust/pytests/wrapper.rs b/rust/pytests/wrapper.rs
index 2da7ea8..9fd65e7 100644
--- a/rust/pytests/wrapper.rs
+++ b/rust/pytests/wrapper.rs
@@ -16,11 +16,13 @@ use bumble::wrapper::{
controller::Controller,
device::Device,
drivers::rtk::DriverInfo,
- hci::packets::{
- AddressType, Error, ErrorCode, ReadLocalVersionInformationBuilder,
- ReadLocalVersionInformationComplete,
+ hci::{
+ packets::{
+ AddressType, ErrorCode, ReadLocalVersionInformationBuilder,
+ ReadLocalVersionInformationComplete,
+ },
+ Address, Error,
},
- hci::Address,
host::Host,
link::Link,
transport::Transport,
diff --git a/rust/src/internal/hci/mod.rs b/rust/src/internal/hci/mod.rs
index 05cc7a6..232c49f 100644
--- a/rust/src/internal/hci/mod.rs
+++ b/rust/src/internal/hci/mod.rs
@@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use crate::internal::hci::packets::{Acl, Command, Error, Event, Packet, Sco};
+pub use pdl_runtime::{Error, Packet};
+
+use crate::internal::hci::packets::{Acl, Command, Event, Sco};
use pdl_derive::pdl;
#[allow(missing_docs, warnings, clippy::all)]
@@ -81,87 +83,10 @@ pub(crate) enum PacketTypeParseError {
actual: PacketType,
},
#[error("Failed to parse packet after header: {error}")]
- PacketParse { error: packets::Error },
-}
-
-// TODO: remove if/when PDL derives this for their Error enum (https://github.com/google/pdl/issues/71)
-impl PartialEq<Self> for packets::Error {
- fn eq(&self, other: &Self) -> bool {
- match (self, other) {
- (Error::InvalidPacketError, Error::InvalidPacketError) => true,
- (
- Error::ConstraintOutOfBounds {
- field: field1,
- value: value1,
- },
- Error::ConstraintOutOfBounds {
- field: field2,
- value: value2,
- },
- ) => field1 == field2 && value1 == value2,
- (
- Error::InvalidFixedValue {
- expected: expected1,
- actual: actual1,
- },
- Error::InvalidFixedValue {
- expected: expected2,
- actual: actual2,
- },
- ) => expected1 == expected2 && actual1 == actual2,
- (
- Error::InvalidLengthError {
- obj: obj1,
- wanted: wanted1,
- got: got1,
- },
- Error::InvalidLengthError {
- obj: obj2,
- wanted: wanted2,
- got: got2,
- },
- ) => obj1 == obj2 && wanted1 == wanted2 && got1 == got2,
- (
- Error::InvalidArraySize {
- array: array1,
- element: element1,
- },
- Error::InvalidArraySize {
- array: array2,
- element: element2,
- },
- ) => array1 == array2 && element1 == element2,
- (Error::ImpossibleStructError, Error::ImpossibleStructError) => true,
- (
- Error::InvalidEnumValueError {
- obj: obj1,
- field: field1,
- value: value1,
- type_: type_1,
- },
- Error::InvalidEnumValueError {
- obj: obj2,
- field: field2,
- value: value2,
- type_: type_2,
- },
- ) => obj1 == obj2 && field1 == field2 && value1 == value2 && type_1 == type_2,
- (
- Error::InvalidChildError {
- expected: expected1,
- actual: actual1,
- },
- Error::InvalidChildError {
- expected: expected2,
- actual: actual2,
- },
- ) => expected1 == expected2 && actual1 == actual2,
- _ => false,
- }
- }
+ PacketParse { error: Error },
}
-impl From<packets::Error> for PacketTypeParseError {
+impl From<Error> for PacketTypeParseError {
fn from(error: Error) -> Self {
Self::PacketParse { error }
}
diff --git a/rust/src/internal/hci/tests.rs b/rust/src/internal/hci/tests.rs
index 3bd7d17..7962c88 100644
--- a/rust/src/internal/hci/tests.rs
+++ b/rust/src/internal/hci/tests.rs
@@ -13,9 +13,9 @@
// limitations under the License.
use crate::internal::hci::{
- packets::{self, Event, EventBuilder, EventCode, Packet, Sco},
- parse_with_expected_packet_type, prepend_packet_type, PacketType, PacketTypeParseError,
- WithPacketType,
+ packets::{Event, EventBuilder, EventCode, Sco},
+ parse_with_expected_packet_type, prepend_packet_type, Error, Packet, PacketType,
+ PacketTypeParseError, WithPacketType,
};
use bytes::Bytes;
@@ -78,7 +78,7 @@ fn test_packet_roundtrip_with_type() {
struct FakePacket;
impl FakePacket {
- fn parse(_bytes: &[u8]) -> Result<Self, packets::Error> {
+ fn parse(_bytes: &[u8]) -> Result<Self, Error> {
Ok(Self)
}
}
diff --git a/rust/src/wrapper/hci.rs b/rust/src/wrapper/hci.rs
index 21f5bd0..b029a65 100644
--- a/rust/src/wrapper/hci.rs
+++ b/rust/src/wrapper/hci.rs
@@ -14,7 +14,7 @@
//! HCI
-pub use crate::internal::hci::packets;
+pub use crate::internal::hci::{packets, Error, Packet};
use crate::{
internal::hci::WithPacketType,