clockwork_tuples/traits/
has_one_of.rs1use crate::{
2 index::{Here, Index, There},
3 traits::has::ConsHas,
4};
5
6pub trait ConsHasOne<Query, QueryIdx, Idx = Here> {
12 type Has;
14
15 fn cons_get_one(self) -> Self::Has;
17
18 fn cons_get_one_ref(&self) -> &Self::Has;
20}
21
22impl<Query, QueryIdx, Head, Tail> ConsHasOne<Query, QueryIdx, Here> for (Head, Tail)
23where
24 Query: ConsHas<Head, QueryIdx>,
25{
26 type Has = Head;
27
28 fn cons_get_one(self) -> Self::Has { self.0 }
29 fn cons_get_one_ref(&self) -> &Self::Has { &self.0 }
30}
31
32impl<Query, QueryIdx, Head, Tail, TailIdx: Index> ConsHasOne<Query, QueryIdx, There<TailIdx>> for (Head, Tail)
33where
34 Tail: ConsHasOne<Query, QueryIdx, TailIdx>,
35{
36 type Has = <Tail as ConsHasOne<Query, QueryIdx, TailIdx>>::Has;
37
38 fn cons_get_one(self) -> Self::Has { self.1.cons_get_one() }
39 fn cons_get_one_ref(&self) -> &Self::Has { self.1.cons_get_one_ref() }
40}