Conflicting implementations of trait in Rust

后端 未结 1 1755
慢半拍i
慢半拍i 2020-11-30 15:02

I want to implement a custom trait for &\'a str and for integer numbers up to i32, but Rust does not allow me to:

use std::conv         


        
相关标签:
1条回答
  • 2020-11-30 15:42

    The fact that &'a str does not implement Into<i32> is not taken into account, because there is no guarantee that it couldn't be added later. This would then break your code.

    So if this were allowed the possible breakage would make it harder to add implementations to library traits.

    Unfortunately I couldn't find documentation for that, neither in The Rust Programming Language Book nor in the Reference Manual.

    The best I could find is RFC 1023, which says that a crate [...] cannot rely that Type: !Trait holds unless Type or Trait is local.

    0 讨论(0)
提交回复
热议问题