Why was `mut_slice_from` renamed to `slice_from_mut`?

This really sounds wrong. Method names are normally about what you get and not on what you use them. mut_slice_from sounds much more natural than slice_from_mut because one normally explicitly wants a mutable slice and not a slice of something mutable.

there is style guide to use _mut suffix throughout the API for consistency.

I agree that the method name is misleading, but in practice I’ll use the [mut from..] syntax sugar so it doesn’t really bothers me. Anyhow, if you want to raise your concerns to the core-devs, I’ll suggest that you leave a message on the PR that introduced the change or open an issue in the rust-lang repo and ping @aturon - I think it’s more likely that you’ll get an answer from the core-devs if you do that.

For reference, this change was part of the general conventions for ownership variants. The general feeling was that having a simple, consistent placement for a _mut qualifier was better than trying to special-case rules (and the existing libraries had been pretty inconsistent about the placement).

Owned by default

If foo uses/produces owned data by default, use:

  • The _ref suffix (e.g. foo_ref) for the immutably borrowed variant.
  • The _mut suffix (e.g. foo_mut) for the mutably borrowed variant.

Exceptions

For mutably borrowed variants, if the mut qualifier is part of a type name (e.g. as_mut_slice), it should appear as it would appear in the type.

I interpret mut_slice_from as saying ‘take a mutable slice from …’, in the same way that as_mut_slice is ‘as a mutable slice’. This makes me think that according to these rules, it should be mut_slice_from.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.