Skip to content

Could we access associated type out of a struct? #38774

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

Closed
hicqu opened this issue Jan 2, 2017 · 2 comments
Closed

Could we access associated type out of a struct? #38774

hicqu opened this issue Jan 2, 2017 · 2 comments

Comments

@hicqu
Copy link

hicqu commented Jan 2, 2017

here is a piece of code:

trait A {
    type AA;
}

struct S;

impl A for S {
    type AA = String;
}

// how to access AA out of S?
let aa_instance = S::AA::new();    // wrong
let aa_instance = (S as A)::AA::new();    // wrong

could you help me? Thanks!

@petrochenkov
Copy link
Contributor

@hicqu

let aa_instance = <S as A>::AA::new();

S::AA::new() is supposed to work too, but it's not implemented yet. It's a long standing issue and the fix is non-trivial.

@steveklabnik
Copy link
Member

@hicqu generally, http://users.rust-lang.org/ is the right place to ask for help.

Since @petrochenkov has given you an answer, I'm going to give this a close. Thanks!

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

3 participants