Viewing one of two views with Either
#219
Labels
A - Querying
Area: Querying components of entities.
C - Enhancement
Category: New feature or request.
C - Usability
Category: How easy it is for users to use the library.
P - Low
Priority: Not particularly urgent.
S - Needs Investigation
Status: Further investigation is needed.
V - Minor Breaking Change
Versioning: Requires a minor bump according to semver.
Just an idea I had this afternoon:
There may be times where we want to have a view on exactly one of two component types. For example, a system could want entities that contain either component
A
or componentB
, but not both, and obtain either a mutable reference toA
or an immutable reference toB
. We can do this now with a view likeViews!(&mut A, &B)
combined with a filter to express an XOR (not going to write it out because it will be long), but we still have to match on both views in the iteration, and have a weird case where the views seem like they can both beNone
or both beSome
, but the filter has to expressly forbid it.To make this easier, I think we should add new view type in
Either<&mut A, &B>
(or whatever other views we want to put in there). This will, naturally, imply the XOR filter, but will also represent the exclusive disjunction directly in the view. There is no question about whether neither or both components is valid, because those states are no longer valid at all.As far as claims go, a view of this type will make claims on components viewed in both sides. This can also be used for
EntryViews
, but I'm not sure what this will mean for internal queries: will they be allowed to query both components A and B together? There may also be some problems with subviews.For resource views, this doesn't really make much sense, since both resources will always exist if they are contained in the resource component list. Just as
entity::Identifier
does not view resources, I think it best to not view them withEither
(orOption
, really, but at least that makes sense in that it has ).There may be some use in nesting these views. If there are three components that want to be viewed with exclusive disjunction, this could be expressed with a nested
Either<&A, Either<&B, &C>>
. With a view like this, we still have only one valid state, and the filter should naturally follow.The text was updated successfully, but these errors were encountered: