mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-27 04:50:40 +00:00
derive: remove trait BufferFmt
This commit is contained in:
parent
f62cdfb49a
commit
58bb4d921f
@ -363,7 +363,7 @@ impl<'a> Generator<'a, '_> {
|
||||
if i > 0 {
|
||||
buf.write_token(Token![,], span);
|
||||
}
|
||||
buf.write(self.visit_arg(ctx, arg, span)?, ctx.template_span);
|
||||
buf.write_tokens(self.visit_arg(ctx, arg, span)?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -292,11 +292,9 @@ impl<'a> Generator<'a, '_> {
|
||||
let arg = self.visit_arg(ctx, filter, ctx.span_for_node(filter.span()))?;
|
||||
|
||||
let tmp = tmp.into_token_stream();
|
||||
quote_into!(buf, span, { askama::filters::reject(
|
||||
#tmp,
|
||||
// coerce [T, &T, &&T...] to &T
|
||||
(&&&(#arg))
|
||||
as &_)?
|
||||
quote_into!(buf, span, {
|
||||
// coerce [T, &T, &&T...] to &T
|
||||
askama::filters::reject(#tmp, (&&&(#arg)) as &_)?
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -580,9 +580,11 @@ impl<'a> Generator<'a, '_> {
|
||||
Ok(size_hint)
|
||||
})?;
|
||||
let cond_buf = cond_buf.into_token_stream();
|
||||
loop_buf.write_tokens(quote_spanned!(span=> if !#var_did_loop {
|
||||
#cond_buf
|
||||
}));
|
||||
quote_into!(&mut loop_buf, span, {
|
||||
if !#var_did_loop {
|
||||
#cond_buf
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.handle_ws(loop_block.ws3);
|
||||
size_hint2 = this.write_buf_writable(ctx, &mut loop_buf)?;
|
||||
@ -1159,10 +1161,7 @@ impl<'a> Generator<'a, '_> {
|
||||
// multiple times, e.g. in the case of macro
|
||||
// parameters being used multiple times.
|
||||
_ => {
|
||||
value.write(
|
||||
this.visit_expr_root(&call_ctx, expr)?,
|
||||
span_span,
|
||||
);
|
||||
value.write_tokens(this.visit_expr_root(&call_ctx, expr)?);
|
||||
// We need to normalize the arg to write it, thus we need to add it to
|
||||
// locals in the normalized manner
|
||||
let id = field_new(arg, span_span);
|
||||
|
@ -119,6 +119,16 @@ impl ToTokens for Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for Buffer {
|
||||
type Item = <TokenStream as IntoIterator>::Item;
|
||||
type IntoIter = <TokenStream as IntoIterator>::IntoIter;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.buf.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl Buffer {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
@ -154,29 +164,24 @@ impl Buffer {
|
||||
self.string_literals.push((literal, span));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn into_token_stream(mut self) -> TokenStream {
|
||||
self.handle_str_lit();
|
||||
self.buf
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn is_discard(&self) -> bool {
|
||||
self.discard
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn set_discard(&mut self, discard: bool) {
|
||||
self.discard = discard;
|
||||
}
|
||||
|
||||
pub(crate) fn write(&mut self, src: impl BufferFmt, span: proc_macro2::Span) {
|
||||
if self.discard {
|
||||
return;
|
||||
}
|
||||
|
||||
self.handle_str_lit();
|
||||
src.append_to(&mut self.buf, span);
|
||||
}
|
||||
|
||||
pub(crate) fn write_tokens(&mut self, src: TokenStream) {
|
||||
#[inline]
|
||||
pub(crate) fn write_tokens(&mut self, src: impl IntoIterator<Item = TokenTree>) {
|
||||
if self.discard {
|
||||
return;
|
||||
}
|
||||
@ -269,16 +274,6 @@ impl Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait BufferFmt {
|
||||
fn append_to(self, buf: &mut TokenStream, span: proc_macro2::Span);
|
||||
}
|
||||
|
||||
impl BufferFmt for TokenStream {
|
||||
fn append_to(self, buf: &mut TokenStream, _span: proc_macro2::Span) {
|
||||
buf.extend(self);
|
||||
}
|
||||
}
|
||||
|
||||
/// Similar to `write!(dest, "{src:?}")`, but only escapes the strictly needed characters,
|
||||
/// and without the surrounding `"…"` quotation marks.
|
||||
pub(crate) fn string_escape(dest: &mut String, src: &str) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user