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

[Rustonomicon] Show how to convert a trait object into concrete type #28571

Closed
Havvy opened this issue Sep 21, 2015 · 5 comments
Closed

[Rustonomicon] Show how to convert a trait object into concrete type #28571

Havvy opened this issue Sep 21, 2015 · 5 comments

Comments

@Havvy
Copy link
Contributor

Havvy commented Sep 21, 2015

Last night somebody asked how to convert a trait object where they knew the concrete type into the concrete type. I tried looking for the answer in the Rustonomicon, but alas, no answer was found. Should this be in there?

The answer has to do with transmuting into std::raw::TraitObject. Even if it's just a link to that type from the transmutation page, I think it's important to explicitly show that it is possible. One issue though, is that std::raw::TraitObject is currently unstable as per issue #27751.

@steveklabnik
Copy link
Member

/cc @gankro

@Gankra
Copy link
Contributor

Gankra commented Sep 22, 2015

I was under the impression that the lang team (cc @nikomatsakis -- can't ping lang myself) wasn't happy with std::raw::TraitObject, so I'm kinda iffy about talking about it. Especially because this is a really specific usecase that's kinda sketchy right now. IDK. Maybe @aturon's inheritance stuff is the way forward?

@steveklabnik
Copy link
Member

That's what I was under the impression of too

On Sep 21, 2015, at 21:41, Alexis Beingessner notifications@github.com wrote:

I was under the impression that the lang team (cc @nikomatsakis -- can't ping lang myself) wasn't happy with std::raw::TraitObject, so I'm kinda iffy about talking about it. Especially because this is a really specific usecase that's kinda sketchy right now. IDK. Maybe @aturon's inheritance stuff is the way forward?


Reply to this email directly or view it on GitHub.

@aturon
Copy link
Member

aturon commented Sep 22, 2015

Yes, we don't have a stable, recommended way to do this at the moment.

Ultimately, we plan to support "upcasting" in traits (so that if you have trait Foo: Any you can go from &Foo to &Any). That will allow you to inherit from Any to get the kind of downcasting you want. It shouldn't be too hard, but it's not on anyone's plate at the moment.

@steveklabnik
Copy link
Member

Okay! Giving this a close, then.

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

No branches or pull requests

4 participants