nt_time/file_time/
rand.rs

1// SPDX-FileCopyrightText: 2024 Shun Sakai
2//
3// SPDX-License-Identifier: Apache-2.0 OR MIT
4
5//! Implementations of [`rand`] for [`FileTime`].
6
7use rand::{
8    Rng,
9    distr::{Distribution, StandardUniform},
10};
11
12use super::FileTime;
13
14impl Distribution<FileTime> for StandardUniform {
15    #[inline]
16    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> FileTime {
17        FileTime::new(rng.random())
18    }
19}
20
21#[cfg(test)]
22mod tests {
23    use rand::rngs::mock::StepRng;
24
25    use super::*;
26
27    #[test]
28    fn sample() {
29        let mut rng = StepRng::new(0, 1);
30        let buf: [FileTime; 4] = rng.random();
31        assert_eq!(
32            buf,
33            [
34                FileTime::new(0),
35                FileTime::new(1),
36                FileTime::new(2),
37                FileTime::new(3)
38            ]
39        );
40    }
41}