I suspect this is because both Index and Vec are public. That error exists to try and protect people from accidentally exposing uncallable interfaces (i.e. it's public, but requires something private to call).
Seems like this particular case could maybe be relaxed.
You can create a newtype that has a single field that consists of your enum. The newtype will be public, but the field can be private. In this way, you will have a public type that can be referred to from outside your module, but the contents are still private. (playpen)
pub struct SomeEnumWrapper(SomeEnum);
impl<'a> Index<SomeEnumWrapper> for Vec<&'a str> {
type Output = str;
fn index(&self, idx: SomeEnumWrapper) -> &str {
self[idx.0 as usize]
}
}
How is the existence of a data type an implementation detail? You don't need to make the field public, nor does it have to have any public methods. It can be as opaque as you want; it just has to have a name.
"How is the existence of a data type an implementation detail?"
The enum is used as indexes into a vector of strings that was created by splitting a string. Effectively I want to turn the string values in the vector into a higher level abstraction that is typed (not a struct of strings).
The entire point of the crate is that users of the crate should not have to worry about the original string of values. So exposing the enum (or a wrapper) is defeating the purpose of the crate. Also, that enum could change over time as new fields are added to the original strings. Users should only have to worry about the higher level struct not the array of string values or the indexes of those string values.
Therefore by making the enum or a wrapper of the enum public, it's exposing implementation details. That wrapper or the enum itself becomes part of the public API. And experience has shown that users will use anything that's public.
Also, now that I've done the implementation of a newtype, I also don't like the newtype pattern because it's an unnecessary level of indirection. Instead of using the enum I have to use the wrapper and, again, there's almost no value in the wrapper. So I've rejected the newtype pattern for this case.
In particular, impl Index<SomeEnum> for Vec is considered a private impl, because it has private trait Index<SomeEnum>, and the trait Index<SomeEnum> is considered private because it has private component SomeEnum.