use std::{fmt, pin::Pin};
use futures_core::Stream;
use super::{Bytes, HeaderMap, TransportError};
#[cfg(not(target_arch = "wasm32"))]
pub type ByteStream = Pin<Box<dyn Stream<Item = Result<Bytes, TransportError>> + Send + 'static>>;
#[cfg(target_arch = "wasm32")]
pub type ByteStream = Pin<Box<dyn Stream<Item = Result<Bytes, TransportError>> + 'static>>;
pub enum HttpBody {
Bytes(Bytes),
Stream(ByteStream),
}
impl fmt::Debug for HttpBody {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Bytes(bytes) => f.debug_struct("Bytes").field("len", &bytes.len()).finish(),
Self::Stream(_) => f.write_str("Stream(..)"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StreamFraming {
Sse,
JsonArray,
NdJson,
}
#[cfg(not(target_arch = "wasm32"))]
pub type PartStream =
Pin<Box<dyn Stream<Item = Result<MultipartPart, TransportError>> + Send + 'static>>;
#[cfg(target_arch = "wasm32")]
pub type PartStream = Pin<Box<dyn Stream<Item = Result<MultipartPart, TransportError>> + 'static>>;
pub struct Multipart {
pub parts: PartStream,
}
impl fmt::Debug for Multipart {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Multipart { parts: .. }")
}
}
#[derive(Debug)]
pub struct MultipartPart {
pub headers: HeaderMap,
pub body: HttpBody,
}
#[cfg(feature = "schema")]
impl schemars::JsonSchema for MultipartPart {
fn schema_name() -> std::borrow::Cow<'static, str> {
"BinaryPart".into()
}
fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({ "type": "string", "format": "binary" })
}
}