[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250610132823.3457263-2-fujita.tomonori@gmail.com>
Date: Tue, 10 Jun 2025 22:28:19 +0900
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: a.hindborg@...nel.org,
alex.gaynor@...il.com,
ojeda@...nel.org
Cc: aliceryhl@...gle.com,
anna-maria@...utronix.de,
bjorn3_gh@...tonmail.com,
boqun.feng@...il.com,
dakr@...nel.org,
frederic@...nel.org,
gary@...yguo.net,
jstultz@...gle.com,
linux-kernel@...r.kernel.org,
lossin@...nel.org,
lyude@...hat.com,
rust-for-linux@...r.kernel.org,
sboyd@...nel.org,
tglx@...utronix.de,
tmgross@...ch.edu
Subject: [PATCH v3 1/5] rust: time: Rename Delta's methods from as_* to into_*
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@...nel.org>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.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
Powered by blists - more mailing lists