use serde::Deserialize;
use crate::payload;
use crate::http::ContentType;
use super::json;
#[derive(Clone, Copy, Debug, Deserialize)]
pub enum Format {
#[serde(rename = "json")]
Json,
}
impl Format {
pub fn content_type(self) -> ContentType {
match self {
Format::Json => ContentType::JSON,
}
}
pub fn stream(self, set: payload::Set) -> Stream {
Stream::new(self, set)
}
}
pub struct Stream(StreamInner);
enum StreamInner {
Json(json::OutputStream),
}
impl Stream {
fn new(format: Format, set: payload::Set) -> Self {
Stream(match format {
Format::Json => StreamInner::Json(json::OutputStream::new(set)),
})
}
}
impl Iterator for Stream {
type Item = Vec<u8>;
fn next(&mut self) -> Option<Self::Item> {
match self.0 {
StreamInner::Json(ref mut inner) => inner.next()
}
}
}