| 1 |
mod component; |
| 2 |
pub(super) mod modifier; |
| 3 |
|
| 4 |
use proc_macro::{Literal, TokenStream}; |
| 5 |
|
| 6 |
pub(crate) use self::component::Component; |
| 7 |
use crate::to_tokens::ToTokenStream; |
| 8 |
|
| 9 |
#[allow(variant_size_differences)] |
| 10 |
pub(crate) enum OwnedFormatItem { |
| 11 |
Literal(Box<[u8]>), |
| 12 |
Component(Component), |
| 13 |
Compound(Box<[Self]>), |
| 14 |
Optional(Box<Self>), |
| 15 |
First(Box<[Self]>), |
| 16 |
} |
| 17 |
|
| 18 |
impl ToTokenStream for OwnedFormatItem { |
| 19 |
fn append_to(self, ts: &mut TokenStream) { |
| 20 |
match self { |
| 21 |
Self::Literal(bytes) => quote_append! { ts |
| 22 |
::time::format_description::BorrowedFormatItem::Literal { |
| 23 |
0: #(Literal::byte_string(bytes.as_ref())) |
| 24 |
} |
| 25 |
}, |
| 26 |
Self::Component(component) => quote_append! { ts |
| 27 |
::time::format_description::BorrowedFormatItem::Component { 0: #S(component) } |
| 28 |
}, |
| 29 |
Self::Compound(items) => { |
| 30 |
let items = items |
| 31 |
.into_vec() |
| 32 |
.into_iter() |
| 33 |
.map(|item| quote! { #S(item), }) |
| 34 |
.collect::<TokenStream>(); |
| 35 |
quote_append! { ts |
| 36 |
::time::format_description::BorrowedFormatItem::Compound { 0: &[#S(items)] } |
| 37 |
} |
| 38 |
} |
| 39 |
Self::Optional(item) => quote_append! {ts |
| 40 |
::time::format_description::BorrowedFormatItem::Optional { 0: &#S(*item) } |
| 41 |
}, |
| 42 |
Self::First(items) => { |
| 43 |
let items = items |
| 44 |
.into_vec() |
| 45 |
.into_iter() |
| 46 |
.map(|item| quote! { #S(item), }) |
| 47 |
.collect::<TokenStream>(); |
| 48 |
quote_append! { ts |
| 49 |
::time::format_description::BorrowedFormatItem::First { 0: &[#S(items)] } |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
} |