use crate::{
enclosed::{
self, simple_escape, simple_query, SimpleEnclosedTemplateSystem, SimpleEscapeParser,
SimpleQueryParser,
},
iter::{EagerParseIter, LazyParseIter, ParsedTemplate},
EnclosedTemplateParser, IntoTemplateSystem, Template, TemplateApplicationError,
};
use core::{convert::Infallible, fmt};
pub fn simple_curly_braces() -> SimpleCurlyBraces {
enclosed::Parser::curly_braces()
.with_escape_parser(SimpleEscapeParser)
.with_query_parser(SimpleQueryParser)
.into_template_system()
}
pub type SimpleCurlyBraces = SimpleEnclosedTemplateSystem<'static>;
pub type LazilyParsed<'a, Query> = Template<
LazyParseIter<'a, EnclosedTemplateParser<SimpleEscapeParser, SimpleQueryParser>>,
Query,
>;
pub use LazilyParsed as LazilyParsedTemplate;
#[cfg_attr(
feature = "std",
doc = r"Error type of [`LazilyParsedTemplate::to_string`] and [`LazilyParsedTemplate::write_to`]."
)]
#[cfg_attr(
not(feature = "std"),
doc = r"Error type of [`LazilyParsedTemplate::write_to`]."
)]
pub type LazilyParsedApplicationError<QueryError> = TemplateApplicationError<
enclosed::ParseError<simple_escape::ParseError, simple_query::ParseError>,
QueryError,
fmt::Error,
>;
pub type EagerlyParsed<SegmentContainer, Query> = ParsedTemplate<SegmentContainer, Query>;
pub type EagerParseError =
enclosed::ParseError<simple_escape::ParseError, simple_query::ParseError>;
pub type EagerlyParsedTemplate<SegmentIter, Query> = Template<EagerParseIter<SegmentIter>, Query>;
#[cfg_attr(
feature = "std",
doc = r"Error type of [`EagerlyParsedTemplate::to_string`] and [`EagerlyParsedTemplate::write_to`]."
)]
#[cfg_attr(
not(feature = "std"),
doc = r"Error type of [`EagerlyParsedTemplate::write_to`]."
)]
pub type EagerlyParsedApplicationError<QueryError> =
TemplateApplicationError<Infallible, QueryError, fmt::Error>;
#[cfg(feature = "std")]
#[cfg(test)]
mod std_tests {
use super::{
simple_curly_braces, EagerParseError, EagerlyParsed, EagerlyParsedApplicationError,
EagerlyParsedTemplate, LazilyParsed, LazilyParsedApplicationError, SimpleCurlyBraces,
};
use derive_more::{Display, Error};
#[test]
fn using_type_aliases() {
fn _type_check(short_lived_response: &str) {
#[derive(Debug, Display, Error, Clone, Copy)]
enum QueryError {}
let system: SimpleCurlyBraces = simple_curly_braces();
let lazy_parsed_template: LazilyParsed<'_, _> = system.lazy_parse("");
let lazy_result: Result<String, LazilyParsedApplicationError<QueryError>> =
lazy_parsed_template.to_string(|_| Ok::<_, QueryError>(short_lived_response));
drop(lazy_result);
let eager_parsed_template: Result<
EagerlyParsed<Vec<crate::enclosed::Segment<&str>>, &str>,
EagerParseError,
> = system.eager_parse::<Vec<_>>("");
let eager_parsed_template: EagerlyParsedTemplate<_, &str> =
eager_parsed_template.as_ref().unwrap().to_template();
let eager_result: Result<String, EagerlyParsedApplicationError<QueryError>> =
eager_parsed_template.to_string(|_| Ok::<_, QueryError>(short_lived_response));
drop(eager_result);
}
}
}