diff --git a/Cargo.toml b/Cargo.toml index 49555bba..fcdebb0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" keywords = ["network","protocol","dds","rtps"] license = "Apache-2.0" edition = "2021" -rust-version = "1.73.0" +rust-version = "1.91.0" homepage = "https://atostek.com/en/products/rustdds/" repository = "https://github.com/Atostek/RustDDS" categories = ["network-programming", "science::robotics"] @@ -118,4 +118,4 @@ termion = "4.0.2" [target.'cfg(target_os = "linux")'.dev-dependencies] -procfs = "0.17" # for ddsperf \ No newline at end of file +procfs = "0.17" # for ddsperf diff --git a/src/discovery/discovery_db.rs b/src/discovery/discovery_db.rs index 7f8ff2f7..d5f7027a 100644 --- a/src/discovery/discovery_db.rs +++ b/src/discovery/discovery_db.rs @@ -95,10 +95,8 @@ fn move_by_guid_prefix( from: &mut BTreeMap, to: &mut BTreeMap, ) { - let to_move: Vec = from.range(guid_prefix.range()).map(|(g, _)| *g).collect(); - for guid in to_move { - from.remove(&guid).map(|d| to.insert(guid, d)); - } + let to_move = from.extract_if(guid_prefix.range(), |_, _| true); + to.extend(to_move); } pub(crate) fn discovery_db_read( @@ -258,16 +256,9 @@ impl DiscoveryDB { } fn remove_topic_reader_with_prefix(&mut self, guid_prefix: GuidPrefix) { - // TODO: Implement this using .drain_filter() in BTreeMap once it lands in - // stable. - let to_remove: Vec = self + let _ = self .external_topic_readers - .range(guid_prefix.range()) - .map(|(g, _)| *g) - .collect(); - for guid in to_remove { - self.external_topic_readers.remove(&guid); - } + .extract_if(guid_prefix.range(), |_, _| true); } pub fn remove_topic_reader(&mut self, guid: GUID) { @@ -286,16 +277,9 @@ impl DiscoveryDB { } fn remove_topic_writer_with_prefix(&mut self, guid_prefix: GuidPrefix) { - // TODO: Implement this using .drain_filter() in BTreeMap once it lands in - // stable. - let to_remove: Vec = self + let _ = self .external_topic_writers - .range(guid_prefix.range()) - .map(|(g, _)| *g) - .collect(); - for guid in to_remove { - self.external_topic_writers.remove(&guid); - } + .extract_if(guid_prefix.range(), |_, _| true); } pub fn remove_topic_writer(&mut self, guid: GUID) {