#[allow(
unused_macros,
reason = "may not be used for all feature flag combinations"
)]
macro_rules! bug {
() => { compile_error!("provide an error message to help fix a possible bug") };
($descr:literal $($rest:tt)?) => {
unreachable!(concat!("internal error: ", $descr) $($rest)?)
}
}
#[macro_use] mod quote;
mod date; mod datetime; mod error; #[cfg(any(feature = "formatting", feature = "parsing"))] mod format_description; mod helpers; mod offset; #[cfg(all(feature = "serde", any(feature = "formatting", feature = "parsing")))] mod serde_format_description; mod time; mod to_tokens; mod utc_datetime;
#[cfg(any(feature = "formatting", feature = "parsing"))] use std::iter::Peekable;
#[cfg(all(feature = "serde", any(feature = "formatting", feature = "parsing")))] use proc_macro::Delimiter; use proc_macro::TokenStream; #[cfg(any(feature = "formatting", feature = "parsing"))] use proc_macro::TokenTree;
// First, the optional format description version. let version = parse_format_description_version::<true>(&mut tokens)?;
// Then, the visibility of the module. let visibility = parse_visibility(&mut tokens)?;
// Next, an identifier (the desired module name) let mod_name = match tokens.next() {
Some(TokenTree::Ident(ident)) => Ok(ident),
Some(tree) => Err(Error::UnexpectedToken { tree }),
None => Err(Error::UnexpectedEndOfInput),
}?;
// Followed by a comma
helpers::consume_punct(',', &mut tokens)?;
// Then, the type to create serde serializers for (e.g., `OffsetDateTime`). let formattable = match tokens.next() {
Some(tree @ TokenTree::Ident(_)) => Ok(tree),
Some(tree) => Err(Error::UnexpectedToken { tree }),
None => Err(Error::UnexpectedEndOfInput),
}?;
// Another comma
helpers::consume_punct(',', &mut tokens)?;
// We now have two options. The user can either provide a format description as a string or // they can provide a path to a format description. If the latter, all remaining tokens are // assumed to be part of the path. let (format, format_description_display) = match tokens.peek() { // string literal
Some(TokenTree::Literal(_)) => { let (span, format_string) = helpers::get_string_literal(tokens)?; let items = format_description::parse_with_version(version, &format_string, span)?; let items: TokenStream = items
.into_iter()
.map(|item| quote_! { #S(item), })
.collect(); let items = quote_! { const { use ::time::format_description::{*, modifier::*};
&[#S(items)] as StaticFormatDescription
}
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.