From 467193ca41fc2cb49e9be771fc60c7058a738b11 Mon Sep 17 00:00:00 2001 From: Sergei Zaychenko Date: Thu, 15 Aug 2024 21:47:11 +0300 Subject: [PATCH] v0.9.1: fixed metadata filters with chained catalogs (#12) --- CHANGELOG.md | 5 +++++ Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- dill/src/catalog.rs | 6 +++--- dill/tests/tests/test_metadata.rs | 19 ++++++++++++++++++- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e75c12f..ed4ce9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.1] - 2024-08-15 +### Fixed +- `Catalog::builders_for_with_meta()` works corectly for chained catalogs + + ## [0.9.0] - 2024-07-29 ### Added - It's now possible to associate custom static metadata with builders: diff --git a/Cargo.lock b/Cargo.lock index 98f52f2..81b82ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "dill" -version = "0.9.0" +version = "0.9.1" dependencies = [ "dill-impl", "multimap", @@ -13,7 +13,7 @@ dependencies = [ [[package]] name = "dill-impl" -version = "0.9.0" +version = "0.9.1" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 5a20d47..50d9994 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["dill-impl", "dill"] [workspace.package] -version = "0.9.0" +version = "0.9.1" edition = "2021" readme = "README.md" homepage = "https://github.com/sergiimk/dill-rs" @@ -52,4 +52,4 @@ multiple_crate_versions = { level = "allow", priority = 1 } [workspace.dependencies] -dill-impl = { path = "dill-impl", version = "0.9.0" } +dill-impl = { path = "dill-impl", version = "0.9.1" } diff --git a/dill/src/catalog.rs b/dill/src/catalog.rs index 896feb1..a0c438e 100644 --- a/dill/src/catalog.rs +++ b/dill/src/catalog.rs @@ -67,7 +67,7 @@ impl Catalog { pub fn builders_for_with_meta<'a, Iface, Meta>( &'a self, - pred: impl Fn(&Meta) -> bool + 'a, + pred: impl Fn(&Meta) -> bool + Copy + 'a, ) -> Box> + 'a> where Iface: 'static + ?Sized, @@ -77,10 +77,10 @@ impl Catalog { let bindings = self.0.bindings.get_vec(&iface_type); let it_bindings = - TypecastPredicateBuilderIterator::new(bindings, move |b| b.metadata_contains(&pred)); + TypecastPredicateBuilderIterator::new(bindings, move |b| b.metadata_contains(pred)); if let Some(chained_catalog) = &self.0.chained_catalog { - Box::new(it_bindings.chain(chained_catalog.builders_for::())) + Box::new(it_bindings.chain(chained_catalog.builders_for_with_meta::(pred))) } else { Box::new(it_bindings) } diff --git a/dill/tests/tests/test_metadata.rs b/dill/tests/tests/test_metadata.rs index 6a55a15..3666f03 100644 --- a/dill/tests/tests/test_metadata.rs +++ b/dill/tests/tests/test_metadata.rs @@ -1,4 +1,4 @@ -use dill::Builder; +use dill::{Builder, CatalogBuilder}; #[test] fn test_metadata() { @@ -137,4 +137,21 @@ fn test_metadata() { res.sort(); assert_eq!(res, ["HandlerA: test", "HandlerAB: test"]); + + let chained_cat = CatalogBuilder::new_chained(&cat).build(); + let mut res = chained_cat + .builders_for_with_meta::(|desc: &EventHandlerDesc| { + desc.event_type == "B" + }) + .map(|b| b.instance_type_name()) + .collect::>(); + + res.sort(); + assert_eq!( + res, + [ + "unit::tests::test_metadata::test_metadata::EventHandlerAB", + "unit::tests::test_metadata::test_metadata::EventHandlerB" + ] + ); }