struct_baker/
ops.rs

1use proc_macro2::TokenStream;
2use quote::quote;
3
4use crate::Bake;
5
6impl<B: Bake, C: Bake> Bake for std::ops::ControlFlow<B, C> {
7    fn to_stream(&self) -> TokenStream {
8        match self {
9            std::ops::ControlFlow::Continue(c) => {
10                let c = c.to_stream();
11                quote!(std::ops::ControlFlow::Continue(#c))
12            }
13            std::ops::ControlFlow::Break(b) => {
14                let b = b.to_stream();
15                quote!(std::ops::ControlFlow::Break(#b))
16            }
17        }
18    }
19}
20
21impl<Idx: Bake> Bake for std::ops::Range<Idx> {
22    fn to_stream(&self) -> TokenStream {
23        let std::ops::Range { start, end } = self;
24        let start = start.to_stream();
25        let end = end.to_stream();
26        quote!(#start .. #end)
27    }
28}
29
30impl<Idx: Bake> Bake for std::ops::RangeFrom<Idx> {
31    fn to_stream(&self) -> TokenStream {
32        let std::ops::RangeFrom { start } = self;
33        let start = start.to_stream();
34        quote!(#start..)
35    }
36}
37
38impl<Idx: Bake> Bake for std::ops::RangeTo<Idx> {
39    fn to_stream(&self) -> TokenStream {
40        let std::ops::RangeTo { end } = self;
41        let end = end.to_stream();
42        quote!( .. #end)
43    }
44}
45
46impl<Idx: Bake> Bake for std::ops::RangeInclusive<Idx> {
47    fn to_stream(&self) -> TokenStream {
48        let start = self.start().to_stream();
49        let end = self.end().to_stream();
50        quote!(#start ..= #end)
51    }
52}
53
54impl<Idx: Bake> Bake for std::ops::RangeToInclusive<Idx> {
55    fn to_stream(&self) -> TokenStream {
56        let std::ops::RangeToInclusive { end } = self;
57        let end = end.to_stream();
58        quote!( .. #end)
59    }
60}
61
62impl<T: Bake> Bake for std::ops::Bound<T> {
63    fn to_stream(&self) -> TokenStream {
64        match self {
65            Self::Included(t) => {
66                let t = t.to_stream();
67                quote!(std::ops::Bound::Included(#t))
68            }
69            Self::Excluded(t) => {
70                let t = t.to_stream();
71                quote!(std::ops::Bound::Excluded(#t))
72            }
73            Self::Unbounded => quote!(std::ops::Bound::Unbounded),
74        }
75    }
76}