rust: Use LazyLock over lazy_static and update dependencies LazyLock is a built-in std way to do lazy statics. Remove import of lazy_static and use LazyLock instead since Fuchsia has deprecated import of lazy_static. Update other dependencies to versions that are used in Fuchsia. Test: cargo test Change-Id: Ib8ecbb54b8b60793469d33bdbf3f7f781e147160 Reviewed-on: https://bluetooth-review.googlesource.com/c/bluetooth/+/3040
diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ddc7870..16147a7 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml
@@ -22,14 +22,13 @@ ## External dependencies # Intended to match Fuchsia versions. assert_matches = "1.5.0" -bitfield = "0.14.0" +bitfield = "0.19.4" futures = "=0.3.31" futures-test = "=0.3.31" -lazy_static = "1.5" -log = { version = "0.4.27", features = [ "kv", "std" ] } +log = { version = "0.4.29", features = ["kv", "std"] } num = { version = "0.4.3", features = ["rand"] } -parking_lot = "0.12.4" +parking_lot = "0.12.5" +pin-project = "1.1" pretty_assertions = "1.2.1" -thiserror = "2.0.12" +thiserror = "2.0.18" uuid = { version = "1.1.2", features = ["serde", "v4"] } -pin-project = "1.0.11"
diff --git a/rust/bt-common/Cargo.toml b/rust/bt-common/Cargo.toml index 67db0da..5fb33d8 100644 --- a/rust/bt-common/Cargo.toml +++ b/rust/bt-common/Cargo.toml
@@ -6,6 +6,5 @@ [dependencies] thiserror.workspace = true -lazy_static.workspace = true uuid.workspace = true futures.workspace = true
diff --git a/rust/bt-common/src/lib.rs b/rust/bt-common/src/lib.rs index 1cb2cf0..242228d 100644 --- a/rust/bt-common/src/lib.rs +++ b/rust/bt-common/src/lib.rs
@@ -3,8 +3,6 @@ // found in the LICENSE file. extern crate core as rust_core; -#[macro_use] -extern crate lazy_static; /// Peers are identified by ids, which should be treated as opaque by service /// libraries. Stack implementations should ensure that each PeerId identifies a
diff --git a/rust/bt-common/src/uuids/characteristic_uuids.rs b/rust/bt-common/src/uuids/characteristic_uuids.rs index d42c0db..1ac72d0 100644 --- a/rust/bt-common/src/uuids/characteristic_uuids.rs +++ b/rust/bt-common/src/uuids/characteristic_uuids.rs
@@ -11,8 +11,8 @@ // With a tweak for "CO2 Concentration" #[rustfmt::skip] -lazy_static! { - pub static ref CHARACTERISTIC_UUIDS: HashMap<Uuid, AssignedUuid> = assigned_uuid_map!( +pub static CHARACTERISTIC_UUIDS: std::sync::LazyLock<HashMap<Uuid, AssignedUuid>> = std::sync::LazyLock::new(|| { + assigned_uuid_map!( (0x2A00, "Device Name", "org.bluetooth.characteristic.gap.device_name"), (0x2A01, "Appearance", "org.bluetooth.characteristic.gap.appearance"), (0x2A02, "Peripheral Privacy Flag", "org.bluetooth.characteristic.gap.peripheral_privacy_flag"), @@ -467,5 +467,5 @@ (0x2C02, "UGT Features", "org.bluetooth.characteristic.ugt_features"), (0x2C03, "BGS Features", "org.bluetooth.characteristic.bgs_features"), (0x2C04, "BGR Features", "org.bluetooth.characteristic.bgr_features") - ); -} + ) +});
diff --git a/rust/bt-common/src/uuids/descriptors.rs b/rust/bt-common/src/uuids/descriptors.rs index ec9adad..d5099c3 100644 --- a/rust/bt-common/src/uuids/descriptors.rs +++ b/rust/bt-common/src/uuids/descriptors.rs
@@ -11,8 +11,8 @@ // With a tweak for "CO2 Concentration" #[rustfmt::skip] -lazy_static! { - pub static ref CHARACTERISTIC_UUIDS: HashMap<Uuid, AssignedUuid> = assigned_uuid_map!( +pub static CHARACTERISTIC_UUIDS: std::sync::LazyLock<HashMap<Uuid, AssignedUuid>> = std::sync::LazyLock::new(|| { + assigned_uuid_map!( (0x2900, "Characteristic Extended Properties", "org.bluetooth.descriptor.gatt.characteristic_extended_properties"), (0x2901, "Characteristic User Description", "org.bluetooth.descriptor.gatt.characteristic_user_description"), (0x2902, "Client Characteristic Configuration", "org.bluetooth.descriptor.gatt.client_characteristic_configuration"), @@ -31,5 +31,5 @@ (0x290F, "Complete BR-EDR Transport Block Data", "org.bluetooth.descriptor.complete_br_edr_transport_block_data"), (0x2910, "Observation Schedule", "org.bluetooth.descriptor.observation_schedule"), (0x2911, "Valid Range and Accuracy", "org.bluetooth.descriptor.valid_range_accuracy"), - ); -} + ) +});
diff --git a/rust/bt-common/src/uuids/service_class.rs b/rust/bt-common/src/uuids/service_class.rs index bb0a335..d4b99d7 100644 --- a/rust/bt-common/src/uuids/service_class.rs +++ b/rust/bt-common/src/uuids/service_class.rs
@@ -10,8 +10,8 @@ // Generated with a magic regexp: %s/ - uuid: \(......\)\n name: \(.\+\)\n id: \(.\+\)\n/(\1, "\2", "\3"),\r/g #[rustfmt::skip] -lazy_static! { - pub static ref SERVICE_CLASS_UUIDS: HashMap<Uuid, AssignedUuid> = assigned_uuid_map!( +pub static SERVICE_CLASS_UUIDS: std::sync::LazyLock<HashMap<Uuid, AssignedUuid>> = std::sync::LazyLock::new(|| { + assigned_uuid_map!( (0x1000, "ServiceDiscoveryServerServiceClassID", "org.bluetooth.service_class.service_discovery_server"), (0x1001, "BrowseGroupDescriptorServiceClassID", "org.bluetooth.service_class.browse_group_descriptor"), (0x1101, "SerialPort", "org.bluetooth.profile.serial_port"), @@ -88,5 +88,5 @@ (0x1400, "HDP", "org.bluetooth.profile.health_device"), (0x1401, "HDP Source", "org.bluetooth.service_class.health_device_source"), (0x1402, "HDP Sink", "org.bluetooth.service_class.health_device_sink") - ); -} + ) +});
diff --git a/rust/bt-common/src/uuids/service_uuids.rs b/rust/bt-common/src/uuids/service_uuids.rs index dcd0282..2668164 100644 --- a/rust/bt-common/src/uuids/service_uuids.rs +++ b/rust/bt-common/src/uuids/service_uuids.rs
@@ -10,8 +10,8 @@ // Generated with a magic regexp: %s/ - uuid: \(......\)\n name: \(.\+\)\n id: \(.\+\)\n/(\1, "\2", "\3"),\r/g #[rustfmt::skip] -lazy_static! { - pub static ref SERVICE_UUIDS: HashMap<Uuid, AssignedUuid> = assigned_uuid_map!( +pub static SERVICE_UUIDS: std::sync::LazyLock<HashMap<Uuid, AssignedUuid>> = std::sync::LazyLock::new(|| { + assigned_uuid_map!( (0x1800, "Generic Access", "org.bluetooth.service.generic_access"), (0x1801, "Generic Attribute", "org.bluetooth.service.generic_attribute"), (0x1802, "Immediate Alert", "org.bluetooth.service.immediate_alert"), @@ -81,5 +81,5 @@ (0x1857, "Electronic Shelf Label", "org.bluetooth.service.electronic_shelf_label"), (0x1858, "Gaming Audio", "org.bluetooth.service.gaming_audio"), (0x1859, "Mesh Proxy Solicitation", "org.bluetooth.service.mesh_proxy_solicitation"), - ); -} + ) +});