0

How can I implement Into trait for arbitrary types, or receive same functionality in whatever way?

For example, I'd like to convert usize into Vec<u8>

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Constantine
  • 1,802
  • 3
  • 23
  • 37
  • 1
    Is there anything preventing you from making your own trait? – E_net4 Mar 29 '17 at 16:51
  • 2
    Couple gotchas here: (1) you actually would want to use `From` and flip the types and (2) an implementation like this needs to be either where `usize`, `Vec`, or `From` is defined. Your options are to: make a new wrapper type or make a new trait. – Alec Mar 29 '17 at 16:53
  • As the other commenters have said; this is deliberately disallowed in Rust. You either need to wrap one of the values in a type that you own **or** implement your own trait. You will then own the trait or the type, and will be allowed to implement a trait for it. – Shepmaster Mar 29 '17 at 17:08

0 Answers0