boseiju/utils/
dummy_init.rs

1pub fn dummy<T: DummyInit>() -> T {
2    T::dummy_init()
3}
4
5/// Trait to create a meaningless instance of an object.
6/// Since all parser nodes need to be constructible for id(), this allows to fill in their fields.
7pub trait DummyInit {
8    fn dummy_init() -> Self;
9}
10
11impl<T, const N: usize> DummyInit for arrayvec::ArrayVec<T, N> {
12    fn dummy_init() -> Self {
13        Self::new_const()
14    }
15}
16
17impl<T> DummyInit for Option<T> {
18    fn dummy_init() -> Self {
19        None
20    }
21}