Idea - Burner Traits

This account sole purpose is 1 response and its disposable;

Idea - Burner Trait

  • Why needed
  • Overcome orphan rule when implementing functions to foreign types (most notoriously primitive types)
  • When you don’t care about using this trait’s name in the future to bound generics
  • Syntax
  • In current rust compiler most simply
    imp _ for SomeType
    
    is an error saying “error: expected identifier, found reserved identifier ‘_’”
  • This in the future shouldn’t be an error but a feature that is you can’t bound a generic (e.g T: _) SINCE is a Burner Trait. Its sole purpose to implement foreign types with associated functions (and possibly associated types) to “circumvent” the orphan rule
  • ‘A macro would do’
  • Yes you are correct that a macro would do the job but I counter argue that simply typing first hand
    impl _ for u8,
    
    Is easier than implementing the macro yourself. You can counter argue that “use a lib” would do but some people are the kind of people that prefer to be “minimal dependencies or zero” and such reason is probably due to security concern for depending on libs in general and as such when its update automatically on the dependency and if then becomes malicious like secretly key logging etc, they’re have no awareness as such is happening.

Note: reserved; It mentions “reserved” meaning either there was SIMILAR IDEA to mine without me realising or B, an identifier that shouldn’t be there as rust compiler does this in the form of a error

Edit: Realising the error is actually expected trait when changing to “impl _ to u8”, found type but still the reserved identifier means something

This isn't clear at all what you actually want? You just want to add inherent methods to foreign types? IIRC there was a discussion on allowing this for binary crates (because we know it's a leaf node) but if you want it on library crates you should revisit that discussion because I don't know what changes whether it's spelled impl _ for Foo as a unnameable trait vs being spelled impl Foo as an inherent methods. This also doesn't have anything to do with the orphan rule as far as I can see because that is restricting implementations of foreign traits for foreign types but you want to implement a new private trait for foreign types; which you can already do.

4 Likes