Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata support #11

Merged
merged 4 commits into from
Jul 29, 2024
Merged

Metadata support #11

merged 4 commits into from
Jul 29, 2024

Conversation

sergiimk
Copy link
Member

@sergiimk sergiimk commented Jul 29, 2024

Example:

    #[derive(Debug)]
    struct EventHandlerDesc {
        event_type: &'static str,
    }

    trait EventHandler: Send + Sync {
        fn on_event(&self, event: &str) -> String;
    }

    #[dill::component]
    #[dill::interface(dyn EventHandler)]
    #[dill::meta(EventHandlerDesc { event_type: "A"})]
    struct EventHandlerA;
    impl EventHandler for EventHandlerA {
      ...
    }

    #[dill::component]
    #[dill::interface(dyn EventHandler)]
    #[dill::meta(EventHandlerDesc { event_type: "B"})]
    struct EventHandlerB;
    impl EventHandler for EventHandlerB {
      ...
    }

    #[dill::component]
    #[dill::interface(dyn EventHandler)]
    #[dill::meta(EventHandlerDesc { event_type: "A"})]
    #[dill::meta(EventHandlerDesc { event_type: "B"})]
    struct EventHandlerAB;
    impl EventHandler for EventHandlerAB {
      ...
    }


// Usage
catalog.builders_for_with_meta::<dyn EventHandler, _>(
  |desc: &EventHandlerDesc| desc.event_type == "B"
)

Copy link
Member

@s373r s373r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT with a minor comment + please update CHANGELOG.md

dill-impl/src/lib.rs Outdated Show resolved Hide resolved
@zaychenko-sergei
Copy link
Contributor

Noticing linear search at runtime to apply the filter, but that's fine. This is better than constructing objects from builders to filter.

@zaychenko-sergei zaychenko-sergei merged commit 9efe795 into master Jul 29, 2024
1 check passed
@zaychenko-sergei zaychenko-sergei deleted the feature/metadata branch July 29, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants