[PATCH v2 5/8] rust: time: Add Instant::from_nanos()

From: Lyude Paul
Date: Tue Apr 15 2025 - 15:51:49 EST


For implementing Rust bindings which can return a point in time.

Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
---
rust/kernel/time.rs | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
index 8d6aa88724ad8..545963140f180 100644
--- a/rust/kernel/time.rs
+++ b/rust/kernel/time.rs
@@ -83,6 +83,14 @@ pub fn elapsed(&self) -> Delta {
pub(crate) fn as_nanos(self) -> i64 {
self.inner
}
+
+ #[expect(unused)]
+ #[inline]
+ pub(crate) fn from_nanos(nanos: i64) -> Self {
+ Self {
+ inner: nanos as bindings::ktime_t,
+ }
+ }
}

impl core::ops::Sub for Instant {
--
2.48.1