Re: [PATCH v1 1/2] rust: time: Rename Delta's methods as_micros_ceil and as_millis
From: Miguel Ojeda
Date: Wed Jun 18 2025 - 05:32:12 EST
On Wed, Jun 18, 2025 at 10:05 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> Why are we renaming them? The stdlib always uses as_* or to_* for copy
> types. In my mind, into_* means that you want to emphasize that you are
> performing a transformation that consumes self and transfers ownership
> of some resource in the process.
>
> See the api guidelines:
> https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv
We may be going in circles here... I think the confusion is all on
what to do for "owned -> owned" `Copy` non-expensive conversions.
I think Tomo sent a patch to change the `as_` and `is_` methods to
take `&self` to be consistent with the guidelines, since they say
there is no "owned -> owned" case for `as_`. Then you mentioned that
`self` is OK and Andreas agreed, and I guess Tomo ended up with
`into_` since `to_` is only for the expensive case, even though it is
not meant for `Copy` types.
In other words, either we say in the kernel we are OK with `as_` for
"owned -> owned" too, or we take `&self`.
Did I get that right, everyone?
Thanks!
Cheers,
Miguel