1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Rust language amplification library providing multiple generic trait
// implementations, type wrappers, derive macros and other language enhancements
//
// Written in 2019-2022 by
//     Dr. Maxim Orlovsky <orlovsky@pandoracore.com>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the MIT License
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

use crate::{Array, Wrapper};

/// Used as an alternative to default for test and prototyping purposes, when a
/// type can't have a default value, but you need to generate some dumb data.
pub trait Dumb
where
    Self: Sized,
{
    /// Returns an object initialized with dumb data
    fn dumb() -> Self;
}

impl Dumb for u8 {
    #[cfg(feature = "rand")]
    fn dumb() -> Self {
        use rand::RngCore;
        rand::thread_rng().next_u32().to_be_bytes()[0]
    }

    #[cfg(not(feature = "rand"))]
    fn dumb() -> Self {
        1
    }
}

impl<T, const LEN: usize> Dumb for Array<T, LEN>
where
    T: Dumb + Copy,
{
    fn dumb() -> Self {
        Self::from_inner([T::dumb(); LEN])
    }
}

// TODO: Implement for main primitive types
// TODO: Implement for main collection types
// TODO: Implement for types defined in this crate