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

Implement LayoutFilter for Box<dyn LayoutFilter + Send> #290

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

zedrian
Copy link

@zedrian zedrian commented Nov 16, 2021

Added implementation of the LayoutFilter trait for Box<dyn LayoutFilter + Send>.

Description

  • Added impl LayoutFilter for Box<dyn LayoutFilter + Send> {...}.
  • Corresponding documentation entry added with an example and motivation explanations.

Motivation and Context

When serializing a World, world- and entity serializers are passed to World::as_serializable() by reference while the layout filter is passed by value - even though LayoutFilter::matches_layout() does not consume the filter object. Because of that, when a user tried to develop a solution that will allow systems to request world serialization (that should be performed outside the Schedule since systems do not have access to the whole World to do that) there was no way to store the desired layout filter in any type-agnostic way.

This change allows storing layout filters inside Boxes and later passing them "as is" to World::as_serializable() without breaking the existing interface.
In particular, this change solves the problem of decoupling the code that requests world serialization from the code that actually performs it, including the layout filter type. So now it's possible for different systems to store serialization requests (including custom layout filters) in Resources that will later be processed altogether outside the Schedule execution.

An additional Send requirement was added to allow to store filters in Resources accessed by systems that don't have to be thread-local.

How Has This Been Tested?

I've tested these changes in my private project, but I've also added a corresponding example to the documentation (that, I suppose, could count as a doc-test).

Checklist:

  • Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme.
  • My code follows the code style of this project.
  • If my change required a change to the documentation I have updated the documentation accordingly.
  • I have updated the content of the book if this PR would make the book outdated.
  • I have added tests to cover my changes.
  • My code is used in an example.

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.

1 participant