r/rust • rust • May 26 '16

Announcing Rust 1.9

http://blog.rust-lang.org/2016/05/26/Rust-1.9.html
301 Upvotes

125 comments sorted by

View all comments

Show parent comments

7

u/Manishearth servo · rust · clippy May 27 '16

It is a technical requirement. By default, you can't have overlapping trait impls, since trait resolution breaks. With the default keyword, you opt in to this behavior, and accept that your own implementation may be overridden. That's not something you want to happen by default.

Eg I like to put fmt::Debug (if not derived) and fmt::Display in its own private strings.rs file. Documentation will show them just fine, everything works, but the implementations are 'hidden' away to reduce clutter.

How is this different than the default tag? I assume that all specializations will show up in the docs regardless.

This has nothing to do with the default tag. Your situation is just a matter of code organization within a single crate, whereas specialization has cross-crate implications.

1

u/mholub May 27 '16

why is it called "default"?

6

u/GolDDranks May 27 '16

Because it marks the default implementation that is being used in absence of specializations.