Sealed trait not implemented for &str


#1

I am facing below error message:

error[E0277]: the trait bound &'a str: core::slice::private_slice_index::Sealed is not satisfied --> src/json.rs:681:10
|
681 | impl<'a> SliceIndex for &'a str {
| ^^^^^^^^^^^^^^^^ the trait core::slice::private_slice_index::Sealed is not implemented for &'a str

error: aborting due to previous error

For,

impl<'a> SliceIndex for &'a str {
type Output=Json;

Looking up into the RFCs, mention something about gating traits from being implemented outside the crate so as to allow API evolution without breaking change. But I am able to implement SliceIndex<Json> for usize. So what is different between usize and &str.

Thanks,


#2

There’s a “hidden” trait bound that you can see here.

This is likely done to control the types you can implement the trait for - you can see usize having an impl of the Sealed trait, implying it’s “blessed”:


#3

Thanks, I grep-ed rust source base for Sealed trait, but my local repo is couple of weeks old :). Will stick with Index trait. Cheers,