-
-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic iterator field for a template #881
Comments
What does the relevant template code look like? |
Tree:
Code: impl < 'a, E : Iterator < Item = String > > ::askama::Template for Enum< 'a, E > {
fn render_into(&self, writer: &mut (impl ::std::fmt::Write + ?Sized)) -> ::askama::Result<()> {
include_bytes! ("/home/path/lib/templates/enum.c.j2") ;
writer.write_str("typedef enum\n{\n ")?;
{
let mut _did_loop = false;
let _iter = (&self.entries).into_iter();
for (entry, _loop_item) in ::askama::helpers::TemplateLoop::new(_iter) {
_did_loop = true;
::std::write!(
writer,
"\n SWM_CANPDU_{expr0},\n ",
expr0 = &::askama::MarkupDisplay::new_unsafe(&(entry), ::askama::Html),
)?;
}
if !_did_loop {
}
}
::std::write!(
writer,
"\n \n SWM_CANPDU_{expr1}_NUMBER_ID,\n}}\nSWM_CANPDU_{expr2}List_priv_t;",
expr1 = &::askama::MarkupDisplay::new_unsafe(&(self.count_prefix), ::askama::Html),
expr2 = &::askama::MarkupDisplay::new_unsafe(&(self.object_name), ::askama::Html),
)?;
::askama::Result::Ok(())
}
const EXTENSION: ::std::option::Option<&'static ::std::primitive::str> =
Some("c")
;
const SIZE_HINT: ::std::primitive::usize =
126
;
const MIME_TYPE: &'static ::std::primitive::str =
"text/plain; charset=utf-8"
;
}
impl < 'a, E : Iterator < Item = String > > ::std::fmt::Display for Enum< 'a, E > {
#[inline]
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
::askama::Template::render_into(self, f).map_err(|_| ::std::fmt::Error {})
}
} |
I just mean the contents of |
Oh sorry about that. Here it is:
|
I guess I could have |
The notion of an |
I need to compute the string values out of a slice of Messages by filtering and mapping. At the end of the chain, I have an
std::iter::Map<...>
which can be seen as animpl Iterator<Item = String>
. At this point I cannot figure out a way to pass this iterator to a Template to loop over it:The compiler returns:
Is there any way to do this, or am I forced to compute the entire list up front?
The text was updated successfully, but these errors were encountered: