diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/time-macros/src/format_description/public/mod.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time-macros/src/format_description/public/mod.rs')
-rw-r--r-- | vendor/time-macros/src/format_description/public/mod.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/time-macros/src/format_description/public/mod.rs b/vendor/time-macros/src/format_description/public/mod.rs new file mode 100644 index 000000000..ccb0b6e2a --- /dev/null +++ b/vendor/time-macros/src/format_description/public/mod.rs @@ -0,0 +1,54 @@ +mod component; +pub(super) mod modifier; + +use proc_macro::{Literal, TokenStream}; + +pub(crate) use self::component::Component; +use crate::to_tokens::ToTokenStream; + +#[allow(variant_size_differences)] +pub(crate) enum OwnedFormatItem { + Literal(Box<[u8]>), + Component(Component), + Compound(Box<[Self]>), + Optional(Box<Self>), + First(Box<[Self]>), +} + +impl ToTokenStream for OwnedFormatItem { + fn append_to(self, ts: &mut TokenStream) { + match self { + Self::Literal(bytes) => quote_append! { ts + ::time::format_description::FormatItem::Literal { + 0: #(Literal::byte_string(bytes.as_ref())) + } + }, + Self::Component(component) => quote_append! { ts + ::time::format_description::FormatItem::Component { 0: #S(component) } + }, + Self::Compound(items) => { + let items = items + .into_vec() + .into_iter() + .map(|item| quote! { #S(item), }) + .collect::<TokenStream>(); + quote_append! { ts + ::time::format_description::FormatItem::Compound { 0: &[#S(items)] } + } + } + Self::Optional(item) => quote_append! {ts + ::time::format_description::FormatItem::Optional { 0: &#S(*item) } + }, + Self::First(items) => { + let items = items + .into_vec() + .into_iter() + .map(|item| quote! { #S(item), }) + .collect::<TokenStream>(); + quote_append! { ts + ::time::format_description::FormatItem::First { 0: &[#S(items)] } + } + } + } + } +} |