Skip to content

Conversation

@zannabianca1997
Copy link

This is an initial implementation for supporting HTML streaming.

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. For now I implemented the support for Axum, as it is the only framework I am used to.

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
                        }
                    }
                }
            }
        }
    )
}

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?

Added a streaming version of `Markup`, with support for Axum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants