Add support for restricting trait implementation for local typesa

As the orphan rule suggest I could implement a local trait to a foreign type,so sometimes people could implement it accidentally,like I want to create a newtype trait


trait newtype{
type output;
fn get(&self)->self::output
fn new(input:output)->Self;
}

struct kg(u32)
impl newtype for kg{
fn get(&self){
    self.0
}

fn new(input:output){
    Self(input);
    }
}

than I relized there is no restriction here,I could implement to every foreign type like u32,u16 which I don't want. Also I wanted to impl Add trait to every newtype which I can't do because of the orphan rule,I want to know the compiler that newtype will be only implemented on local types,so as newtype is also a local trait I could implement Add trait to every newtype

This and related matters have been previously discussed. Most recently at the thread Sealed traits. Also, you should try to format you code using backticks. Write

```rust
trait newtype{
  type output;
  fn get(&self)->self::output
  fn new(input:output)->Self;
}
```

to display

trait newtype{
  type output;
  fn get(&self)->self::output
  fn new(input:output)->Self;
}
3 Likes