Issue by alanfalloon
Thursday Apr 24, 2014 at 02:31 GMT
For earlier discussion, see rust-lang/rust#13721
This issue was labelled with: in the Rust repository
As you know, you can't provide an impl for a trait if neither the type nor the trait are defined in the current crate, you get:
error: cannot provide an extension implementation where both trait and type are not defined in this crate
For public implementations, this makes perfect sense, there are issues with collisions between implementations and sheer surprise. However, for a private implementation of the trait, this is a real hindrance.
Consider the case of std::path::Path not implementing std::fmt::Show. The rationale for closing #13009 is perfectly valid: we don't want people treating paths as strings. However, by refusing to add an implementation of Show, you have made that decision for all programs everywhere. In my case, I had a large struct with numerous Path elements that I wanted to print for debugging, but #[deriving(Show)] won't work because Path has no Show impl, and now I'm stuck either implementing it tediously from scratch, or switching to str for my path names.
The perfect compromise would have been to allow my crate to define a private Show impl for Path. There is precedent for this in other languages, go allows interfaces to implemented anywhere, for example.
Thursday Apr 24, 2014 at 02:31 GMT
For earlier discussion, see rust-lang/rust#13721
This issue was labelled with: in the Rust repository
As you know, you can't provide an impl for a trait if neither the type nor the trait are defined in the current crate, you get:
For public implementations, this makes perfect sense, there are issues with collisions between implementations and sheer surprise. However, for a private implementation of the trait, this is a real hindrance.
Consider the case of
std::path::Pathnot implementingstd::fmt::Show. The rationale for closing #13009 is perfectly valid: we don't want people treating paths as strings. However, by refusing to add an implementation ofShow, you have made that decision for all programs everywhere. In my case, I had a large struct with numerousPathelements that I wanted to print for debugging, but#[deriving(Show)]won't work becausePathhas noShowimpl, and now I'm stuck either implementing it tediously from scratch, or switching tostrfor my path names.The perfect compromise would have been to allow my crate to define a private
Showimpl forPath. There is precedent for this in other languages, go allows interfaces to implemented anywhere, for example.