wg-async icon indicating copy to clipboard operation
wg-async copied to clipboard

Write about how coherence makes it nearly impossible to establish standard traits outside of libstd.

Open nikomatsakis opened this issue 4 years ago • 4 comments

Brief summary

Write about how coherence makes it nearly impossible to establish standard traits outside of libstd.

In a nutshell:

  • If I define a trait that (say) all runtimes should implement, they obviously won't implement it yet; typically I then have to implement it for them, because they don't want to implement some Random Joe's trait;
  • at that point, my trait crate depends on all the runtime crates (albeit with optional features, presumably);
  • now those runtimes can't depend on my trait, so they can't implement it, even if they wanted to!

It's sort of a chicken-and-egg problem that seems like it would be quite hard to get around.

Optional details

  • (Optional) Which character(s) would be the best fit and why?
    • [ ] Alan: the experienced "GC'd language" developer, new to Rust
    • [ ] Grace: the systems programming expert, new to Rust
    • [ ] Niklaus: new programmer from an unconventional background
    • [ ] Barbara: the experienced Rust developer
  • (Optional) Which project(s) would be the best fit and why?
    • List some projects here.
  • (Optional) What are the key points or morals to emphasize?
    • Write some morals here.

nikomatsakis avatar Apr 29 '21 21:04 nikomatsakis

Anecdotally, I think this extends beyond just async: imagine trying to introduce a replacement for serde today.

jonhoo avatar Apr 29 '21 22:04 jonhoo

We will touch a little bit on this in #45. I wonder if the exploration in that story is good enough or if a separate story is needed to really drive home the point.

rylev avatar Apr 30 '21 09:04 rylev

Anecdotally, I think this extends beyond just async: imagine trying to introduce a replacement for serde today.

I had the misfortune of running into something similar with zvariant, where for ser/de to/from the D-Bus format, I need a signature string for the type and hence had to require a trait to be implemented for types that can be ser/de. I provide a derive macro so local types are not a big issue but external types are.

zeenix avatar Apr 30 '21 14:04 zeenix

@jonhoo I definitely agree it extends beyond async

nikomatsakis avatar May 04 '21 01:05 nikomatsakis