diff --git a/examples/single_threaded.rs b/examples/single_threaded.rs index 89f4953c..e8885cdb 100644 --- a/examples/single_threaded.rs +++ b/examples/single_threaded.rs @@ -3,8 +3,47 @@ use std::cell::Cell; use std::rc::Rc; +use hyper::body::{Bytes, HttpBody}; +use hyper::header::{HeaderMap, HeaderValue}; use hyper::service::{make_service_fn, service_fn}; -use hyper::{Body, Error, Response, Server}; +use hyper::{Error, Response, Server}; +use std::marker::PhantomData; +use std::pin::Pin; +use std::task::{Context, Poll}; + +struct Body { + // Our Body type is !Send and !Sync: + _marker: PhantomData<*const ()>, + data: Option, +} + +impl From for Body { + fn from(a: String) -> Self { + Body { + _marker: PhantomData, + data: Some(a.into()), + } + } +} + +impl HttpBody for Body { + type Data = Bytes; + type Error = Error; + + fn poll_data( + self: Pin<&mut Self>, + _: &mut Context<'_>, + ) -> Poll>> { + Poll::Ready(self.get_mut().data.take().map(Ok)) + } + + fn poll_trailers( + self: Pin<&mut Self>, + _: &mut Context<'_>, + ) -> Poll>, Self::Error>> { + Poll::Ready(Ok(None)) + } +} fn main() { pretty_env_logger::init();