lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250504045959.238068-2-fujita.tomonori@gmail.com>
Date: Sun,  4 May 2025 13:59:54 +0900
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: rust-for-linux@...r.kernel.org
Cc: a.hindborg@...nel.org,
	boqun.feng@...il.com,
	frederic@...nel.org,
	lyude@...hat.com,
	tglx@...utronix.de,
	anna-maria@...utronix.de,
	jstultz@...gle.com,
	sboyd@...nel.org,
	ojeda@...nel.org,
	alex.gaynor@...il.com,
	gary@...yguo.net,
	bjorn3_gh@...tonmail.com,
	benno.lossin@...ton.me,
	aliceryhl@...gle.com,
	tmgross@...ch.edu,
	dakr@...nel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH v1 1/5] rust: time: Change Delta methods to take &self instead of self

Change several methods of the `Delta` type in Rust to take `&self`
instead of `self`. These methods do not mutate or consume the `Delta`
value and are more idiomatically expressed as taking a shared
reference. This change improves consistency with common Rust practice
and allows calling these methods on references without requiring an
explicit copy or move of the value.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
---
 rust/kernel/time.rs | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ