Skip to content

Commit

Permalink
v0.9.1: fixed metadata filters with chained catalogs (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaychenko-sergei authored Aug 15, 2024
1 parent 0f3fa57 commit 467193c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
6 changes: 3 additions & 3 deletions dill/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Iterator<Item = TypecastBuilder<'a, Iface>> + 'a>
where
Iface: 'static + ?Sized,
Expand All @@ -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::<Iface>()))
Box::new(it_bindings.chain(chained_catalog.builders_for_with_meta::<Iface, Meta>(pred)))
} else {
Box::new(it_bindings)
}
Expand Down
19 changes: 18 additions & 1 deletion dill/tests/tests/test_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dill::Builder;
use dill::{Builder, CatalogBuilder};

#[test]
fn test_metadata() {
Expand Down Expand Up @@ -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::<dyn EventHandler, _>(|desc: &EventHandlerDesc| {
desc.event_type == "B"
})
.map(|b| b.instance_type_name())
.collect::<Vec<_>>();

res.sort();
assert_eq!(
res,
[
"unit::tests::test_metadata::test_metadata::EventHandlerAB",
"unit::tests::test_metadata::test_metadata::EventHandlerB"
]
);
}

0 comments on commit 467193c

Please sign in to comment.