Bug in the docs? str::find is stable, but std::str::pattern::Pattern isn't

I just noticed that str::find uses std::str::pattern::Pattern in its signature, but while find is stable, Pattern is still experimental. Is this a bug in the docs?

Pattern is indeed not stable. Only concrete implementations of it in the standard library are stable.

3 Likes

So... is this a bug in the docs or not? I agree that only the concrete implementations are stable, and that you need nightly if you want to implement Pattern on your own type, but when I just read the docs it feels like I should be able to implement Pattern.

Maybe I'm just overthinking things again... :man_shrugging:

find is indeed stable, Pattern is indeed unstable, and both are marked accordingly in the docs. Of course you can't implement Pattern because it's unstable, but you can call find because it's stable.

Maybe you're expecting to not be able to call find because it would involve passing a type that implements Pattern, and that's unstable? In that case no, that only requires the type implementing the trait, and even if the trait is unstable the trait implementation just needs to be stable (well, trait implementations can't be unstable, so it just needs to exist)

2 Likes

Yup, that sums up what I was think pretty much exactly. So, no bugs in the docs, just a bug in my understanding of the docs. Thank you!

1 Like

Note that this happens secretly in a few places. For example, when you use ? it's using the unstable Try in std::ops - Rust in what it actually calls.

We try not to do it too often, as things can leak a bit (restricting the flexibility we have to change things later) but it's helpful sometimes to let people call things for std types even if they can't implement things for their own stuff just yet.

Makes sense. I just got concerned precisely because the leaking restricts what you can do with the unstable API in the future. But if you already know about it, then it isn't a big deal, and we can just let this topic go away.

1 Like