Skip to main content

ndjson_iter

Function ndjson_iter 

Source
pub fn ndjson_iter<I, T>(iter: I) -> Response
where I: IntoIterator<Item = T>, I::IntoIter: Send + 'static, T: Serialize + Send + Unpin + 'static,
Expand description

Create an NDJSON response from an iterator.

This is a convenience function for when you have an iterator rather than a stream.

§Example

use fastapi_core::ndjson::ndjson_iter;
use serde::Serialize;

#[derive(Serialize)]
struct User { id: i64, name: String }

let users = vec![
    User { id: 1, name: "Alice".into() },
    User { id: 2, name: "Bob".into() },
];

let response = ndjson_iter(users);