This repository was archived by the owner on Dec 31, 2025. It is now read-only.
Split ToVariant and FromVariant traits#187
Merged
Conversation
This allows types to be separately `ToVariant` and `FromVariant`, enabling `ToVariant`-only types to be returned by exported methods, or the other way around. Also relaxes the `Sized` bound on `ToVariant`, so it can be made into trait objects, and passed across threads in boxes.
karroffel
approved these changes
Aug 29, 2019
Member
karroffel
left a comment
There was a problem hiding this comment.
That looks good to me, thanks a lot! :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Cherry-picked this off #181 because I think it would still be useful out of that PR's context, and can be reviewed individually, for use cases like #185 (comment), where you only really need a one-way conversion.
Related sections from the original PR comment:
Explanation
This allows types to be separately
ToVariantandFromVariant.ToVariantno longer requireSized. Bounds on export function arguments, return values, and property getter / setters are relaxed to require only one of these traits. As such, it's now possible to:FromVariantas an argument. e.g. a custom "options" struct that reads from aDictionary.ToVariantas a return value. e.g.Instance<T>.ToVarianttypes into trait objects and send them through Rust channels:Box<dyn ToVariant + Send + 'static>.All types that previously implement
ToVariantare now alsoFromVariant.Drawbacks
ToVariantimplementations on custom types are void, although a fix is very easy.ToVariantas a bound and callfrom_variantneed to do useFromVariant(orToVariant + FromVariant) instead.