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

Add basic information about associated types #23573

Merged
merged 1 commit into from Mar 25, 2015

Conversation

steveklabnik
Copy link
Member

No description provided.

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@Manishearth
Copy link
Member

Could you add a blurb about stuff like Iterator<Item=Foo> in trait bounds and <T as Iterator>::Item? Both are rather nonintuitive.

% Associated Types

Associated types are a powerful part of Rust's type system. They're related to
the idea of a 'type family,' in other words, grouping multiple types together. That
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comma after quote

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@alexcrichton
Copy link
Member

Associated types can definitely take quite a deep dive into how much we explain them (as @Manishearth pointed out), but I'm not sure how exhaustive this documentation wants to be. I feel like the book wants to stay fairly light so it doesn't really need to go into the gory details of <T as Trait>::Type, but I do agree that Trait<Type=Concrete> would be useful to explain as it shows up pretty commonly and is the only way you can make a trait object of a trait with associated types.


```rust
trait Graph {
type N;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider comparing it to an alias: type Inches = i32 because aliasing may be familiar. It look me a while to realize these both used the same keyword and that an associated type wasn't just using some new syntax someone conjured strictly for this purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than looking like one, they're not really connected in any way though. I'd find this more confusing, I'd think.

@steveklabnik
Copy link
Member Author

I'm not sure how exhaustive this documentation wants to be.

Yeah, at least at the moment, I'd just like to get a solid base in. We currently have no documentation at all for associated types, so I'd like to land the core stuff, and then we can add more later.

@steveklabnik
Copy link
Member Author

I added a section on trait objects which shows off that syntax.

@alexcrichton
Copy link
Member

@bors: r+ f2996c0

yay!

@alexcrichton
Copy link
Member

@bors: rollup

@steveklabnik
Copy link
Member Author

🎊

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 24, 2015
@bors bors merged commit f2996c0 into rust-lang:master Mar 25, 2015
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

Successfully merging this pull request may close these issues.

None yet

6 participants