rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
To: a.hindborg@kernel.org, alex.gaynor@gmail.com, ojeda@kernel.org
Cc: aliceryhl@google.com, anna-maria@linutronix.de,
	bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org,
	frederic@kernel.org, gary@garyguo.net, jstultz@google.com,
	linux-kernel@vger.kernel.org, lossin@kernel.org,
	lyude@redhat.com, rust-for-linux@vger.kernel.org,
	sboyd@kernel.org, tglx@linutronix.de, tmgross@umich.edu
Subject: [PATCH v3 1/5] rust: time: Rename Delta's methods from as_* to into_*
Date: Tue, 10 Jun 2025 22:28:19 +0900	[thread overview]
Message-ID: <20250610132823.3457263-2-fujita.tomonori@gmail.com> (raw)
In-Reply-To: <20250610132823.3457263-1-fujita.tomonori@gmail.com>

Rename Delta's methods that take self from as_* to into_* to align
with Rust naming conventions.

Using `self` is more common Rust practice for small values that can be
freely copied [1].

Clippy warns against using as_* names for trait methods that take self
as follows:

warning: methods called as_* usually take self by reference or self by mutable reference
--> ~/linux/rust/kernel/time/hrtimer.rs:421:17
|
421 |     fn as_nanos(self) -> i64;

Rename the `Delta` struct's methods from as_nanos(), as_micros_ceil(),
and as_millis() to into_nanos(), into_micros_ceil(), and
into_millis(), respectively to maintain consistency with the other
function names.

Link: https://lore.kernel.org/lkml/aD1fgizC4FPT07vt@google.com/ [1]
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
 rust/kernel/time.rs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
index 9fd487276457..2a231c321afa 100644
--- a/rust/kernel/time.rs
+++ b/rust/kernel/time.rs
@@ -261,31 +261,31 @@ pub const fn from_secs(secs: i64) -> Self {
     /// Return `true` if the [`Delta`] spans no time.
     #[inline]
     pub fn is_zero(self) -> bool {
-        self.as_nanos() == 0
+        self.into_nanos() == 0
     }
 
     /// Return `true` if the [`Delta`] spans a negative amount of time.
     #[inline]
     pub fn is_negative(self) -> bool {
-        self.as_nanos() < 0
+        self.into_nanos() < 0
     }
 
     /// Return the number of nanoseconds in the [`Delta`].
     #[inline]
-    pub const fn as_nanos(self) -> i64 {
+    pub const fn into_nanos(self) -> i64 {
         self.nanos
     }
 
     /// Return the smallest number of microseconds greater than or equal
     /// to the value in the [`Delta`].
     #[inline]
-    pub const fn as_micros_ceil(self) -> i64 {
-        self.as_nanos().saturating_add(NSEC_PER_USEC - 1) / NSEC_PER_USEC
+    pub const fn into_micros_ceil(self) -> i64 {
+        self.into_nanos().saturating_add(NSEC_PER_USEC - 1) / NSEC_PER_USEC
     }
 
     /// Return the number of milliseconds in the [`Delta`].
     #[inline]
-    pub const fn as_millis(self) -> i64 {
-        self.as_nanos() / NSEC_PER_MSEC
+    pub const fn into_millis(self) -> i64 {
+        self.into_nanos() / NSEC_PER_MSEC
     }
 }
-- 
2.43.0


  reply	other threads:[~2025-06-10 13:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-10 13:28 [PATCH v3 0/5] rust: time: Convert hrtimer to use Instant and Delta FUJITA Tomonori
2025-06-10 13:28 ` FUJITA Tomonori [this message]
2025-06-10 13:28 ` [PATCH v3 2/5] rust: time: Replace HrTimerMode enum with trait-based mode types FUJITA Tomonori
2025-06-10 13:28 ` [PATCH v3 3/5] rust: time: Add HrTimerExpires trait FUJITA Tomonori
2025-06-10 13:28 ` [PATCH v3 4/5] rust: time: Make HasHrTimer generic over HrTimerMode FUJITA Tomonori
2025-06-12 13:45   ` Andreas Hindborg
2025-06-10 13:28 ` [PATCH v3 5/5] rust: time: Remove Ktime in hrtimer FUJITA Tomonori
2025-06-16 22:07 ` [PATCH v3 0/5] rust: time: Convert hrtimer to use Instant and Delta FUJITA Tomonori
2025-06-17  8:06   ` Andreas Hindborg
2025-06-17 10:37 ` Andreas Hindborg
2025-06-24 11:08   ` Miguel Ojeda
2025-06-24 11:14     ` Andreas Hindborg
2025-06-24 12:24       ` Miguel Ojeda
2025-06-24 13:11         ` Andreas Hindborg
2025-06-24 13:41           ` FUJITA Tomonori
2025-06-24 17:56             ` Andreas Hindborg
2025-06-24 19:03               ` Andreas Hindborg
2025-06-24 23:20                 ` FUJITA Tomonori
2025-06-25  8:19                   ` Andreas Hindborg
2025-06-26  0:12                     ` FUJITA Tomonori
2025-07-04  7:20                       ` Andreas Hindborg
2025-07-10 11:59                         ` Andreas Hindborg
2025-07-10 23:00                           ` FUJITA Tomonori
2025-07-11  6:13                             ` Andreas Hindborg
2025-06-24 21:13           ` Miguel Ojeda
2025-06-24 23:30             ` FUJITA Tomonori
2025-06-25  8:11               ` Miguel Ojeda
2025-06-25  8:30                 ` Andreas Hindborg
2025-06-25  8:28             ` Andreas Hindborg
2025-06-24 11:16   ` Andreas Hindborg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250610132823.3457263-2-fujita.tomonori@gmail.com \
    --to=fujita.tomonori@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=anna-maria@linutronix.de \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=frederic@kernel.org \
    --cc=gary@garyguo.net \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).