[PATCH] rust: time: implement `Display` for `Delta`

Andreas Hindborg posted 1 patch 1 month, 2 weeks ago
rust/kernel/time.rs | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] rust: time: implement `Display` for `Delta`
Posted by Andreas Hindborg 1 month, 2 weeks ago
Implement the `Display` trait for `Delta` so that it can be displayed by a
formatter.

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 rust/kernel/time.rs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
index 6ea98dfcd0278..e18fd17f38c5a 100644
--- a/rust/kernel/time.rs
+++ b/rust/kernel/time.rs
@@ -474,3 +474,9 @@ pub fn rem_nanos(self, dividend: i32) -> Self {
         }
     }
 }
+
+impl kernel::fmt::Display for Delta {
+    fn fmt(&self, f: &mut kernel::fmt::Formatter<'_>) -> kernel::fmt::Result {
+        f.write_fmt(kernel::prelude::fmt!("{}", self.as_nanos()))
+    }
+}

---
base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
change-id: 20260215-time-delta-display-d702e7788d2d

Best regards,
-- 
Andreas Hindborg <a.hindborg@kernel.org>
Re: [PATCH] rust: time: implement `Display` for `Delta`
Posted by Alice Ryhl 1 month, 2 weeks ago
On Sun, Feb 15, 2026 at 09:14:05PM +0100, Andreas Hindborg wrote:
> Implement the `Display` trait for `Delta` so that it can be displayed by a
> formatter.
> 
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
> ---
>  rust/kernel/time.rs | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index 6ea98dfcd0278..e18fd17f38c5a 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -474,3 +474,9 @@ pub fn rem_nanos(self, dividend: i32) -> Self {
>          }
>      }
>  }
> +
> +impl kernel::fmt::Display for Delta {
> +    fn fmt(&self, f: &mut kernel::fmt::Formatter<'_>) -> kernel::fmt::Result {
> +        f.write_fmt(kernel::prelude::fmt!("{}", self.as_nanos()))

I think this can just be

	self.as_nanos().fmt(f)

Though I think it would be nicer to include an 'ns' suffix here so it's
not just the number?

Alice