// Copyright 2024 The ChromiumOS Authors1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34use std::time::Duration;56use libc::timespec;78/// Return a timespec filed with the specified Duration `duration`.9#[allow(clippy::useless_conversion)]10pub fn duration_to_timespec(duration: Duration) -> timespec {11// nsec always fits in i32 because subsec_nanos is defined to be less than one billion.12let nsec = duration.subsec_nanos() as i32;13timespec {14tv_sec: duration.as_secs() as libc::time_t,15tv_nsec: nsec.into(),16}17}181920