Add PropPayload::Any & State::Any for arbitrary data exchange
#120
+648
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ISSUE NUMBER - PULL_REQUEST_TITLE
None
Description
I had found that the current
MockComponentattrandqueryare quite limited in what data they can give out and receive, only being limited toAttrValue,PropPayloadandPropValuevariants.The new
PropPayload::Anymakes use of rustdyn Anyfor being able to store arbitrary data, later being able to downcast to the wanted value.Sadly the implementation is not quite as clean as i wanted it to be, requiring multiple traits working together and for super-trait casting (getting access to
trait Anyfunctions fromPropBoundor other traits).Due to the bound on
PropPayloadrequiringCloneand in std there not being a gooddyn Cloneand manually implementing it would be even more messy thanPartialEq, i chose to use the packagedyn-cloneand manually implementdyn PartialEq, with the limitation of only comparing the same type (ieString("Hello") == String("Hello") == true, but this does not allowString("Hello") == str("Hello") == false). This limitation could be resolved somewhat using a additional bound likeBorrow, but i dont know how useful this would be here.I also added a new example showcasing making use of this new
PropPayload::Any.In the future, this could allow moving things like
::props::datasetinto the place they likely should actually be in, which would betuirealm-std::Chartand removing some extra variants inPropPayload/PropValue.Type of change
Please select relevant options.
Checklist
cargo fmtcargo clippyand reports no warningscfg target_os)PS: this is marked as a DRAFT for feedback before saying it is ready ... treat it basically as a ready Proof-Of-Concept for now.