-
Notifications
You must be signed in to change notification settings - Fork 166
Open
Description
I found maud quite adapt in generating pieces of HTML, and the output of the html macro can easily be converted to an async stream.
By adding a single control flow @yield marking where to pass the buffer forward toward the client I was able to generate a streaming body.
A brief example of the resulting code:
async fn slow_list() -> StreamingMarkup<impl Stream<Item = Markup> + Send + 'static> {
streaming_html!(
(DOCTYPE)
html {
head { title { "Slow list" } }
body {
ol {
@yield
@for i in 0..10 {
li {
({sleep(Duration::from_secs(1)).await; format!("Slept for {}", i+1)})
@yield
}
}
}
}
}
)
}I've opened a PR /pull/490 with the initial implementation and Axum support. This request is still a draft, as it is missing both tests and documentation. I think this feature would be more adapt to a sister/support crate, but I would have to copy all the parsing machinery.
Is this something that could be of interest?
Metadata
Metadata
Assignees
Labels
No labels