Why does `char::is_ascii_uppercase(&self)` take `&self` while `char::is_uppercase(self)` takes `self`?

I was wondering how I should declare a function parameter that takes a small Copy type such as char or f32. (I consider a type small if size_of_type <= 2 * size_of_pointer)

I found this post, but still don't know how stdlib choose between self and &self for a small Copy type.

I basically use self when it is a primitive type, but why does is_ascii_uppercase(&self) take &self?

What is the reason, benefit, or intention of using &self here?

I believe it's just an unfortunate inconsistency that nobody caught when the is_ascii_* methods were stabilized in 1.24 :frowning: All of them take &self while their older unicode counterparts take self.

IIRC it's because they used to be trait methods, where taking & was important for it to work on str too.

So historical sadness.

As a relative newcomer to Rust I’m wondering what options Rust has for fixing this kind of thing

My understanding is that backwards compatibility is generally maintained at almost any cost

Does this mean that small consistency issues that creep into the standard library like this will gradually build up forever or is there any potential for fixing things in a new edition for example?

I guess in certain cases new methods could be introduced and the old ones deprecated, but I imagine that wouldn’t be appropriate in all cases

I'm on libs-api. Compatibility IMO means we ought to be okay with small warts here and there. This is probably one of those.

We do deprecate-and-add-new-APIs in some cases. Unless this particular inconsistency is causing a big problem (I don't think it is), then this is probably not one of those cases. The downsides of deprecating all of the is_ascii methods on char seem like they definitively eclipse any upsides of smoothing out the consistency in the method signatures.

Thanks for the reply, it’s good to get some insight into how things work in this area, much appreciated!

Also a nice example of "practicality beats purity" I think :slight_smile: