use crate::operation;
use bytes::Bytes;
pub trait ParseHttpResponse {
type Output;
fn parse_unloaded(&self, response: &mut operation::Response) -> Option<Self::Output>;
fn parse_loaded(&self, response: &http::Response<Bytes>) -> Self::Output;
}
pub trait ParseStrictResponse {
type Output;
fn parse(&self, response: &http::Response<Bytes>) -> Self::Output;
}
impl<T: ParseStrictResponse> ParseHttpResponse for T {
type Output = T::Output;
fn parse_unloaded(&self, _response: &mut operation::Response) -> Option<Self::Output> {
None
}
fn parse_loaded(&self, response: &http::Response<Bytes>) -> Self::Output {
self.parse(response)
}
}
#[cfg(test)]
mod test {
use crate::body::SdkBody;
use crate::operation;
use crate::response::ParseHttpResponse;
use bytes::Bytes;
use std::mem;
#[test]
fn supports_streaming_body() {
pub struct S3GetObject {
pub body: SdkBody,
}
struct S3GetObjectParser;
impl ParseHttpResponse for S3GetObjectParser {
type Output = S3GetObject;
fn parse_unloaded(&self, response: &mut operation::Response) -> Option<Self::Output> {
let body = mem::replace(response.http_mut().body_mut(), SdkBody::taken());
Some(S3GetObject { body })
}
fn parse_loaded(&self, _response: &http::Response<Bytes>) -> Self::Output {
unimplemented!()
}
}
}
}