Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Sync bound for Body #18

Merged
merged 1 commit into from
Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/chunker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
{
pub(crate) fn with_chunk_size(
cap: usize,
) -> (Self, Box<dyn Stream<Item = Result<D, E>> + Send + Sync>) {
) -> (Self, Box<dyn Stream<Item = Result<D, E>> + Send>) {
assert!(cap > 0);
let (snd, rcv) = mpsc::unbounded();
let body = Box::new(rcv);
Expand Down Expand Up @@ -120,7 +120,7 @@ mod tests {
use std::pin::Pin;

type BoxedError = Box<dyn std::error::Error + 'static + Send + Sync>;
type BodyStream = Box<dyn Stream<Item = Result<Vec<u8>, BoxedError>> + Send + Sync>;
type BodyStream = Box<dyn Stream<Item = Result<Vec<u8>, BoxedError>> + Send>;

async fn to_vec(s: BodyStream) -> Vec<u8> {
Pin::from(s).try_concat().await.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod tests {
type BoxedError = Box<dyn std::error::Error + Sync + Send>;
type CRF = ChunkedReadFile<Bytes, BoxedError>;

async fn to_bytes(s: Box<dyn Stream<Item = Result<Bytes, BoxedError>> + Send + Sync>) -> Bytes {
async fn to_bytes(s: Box<dyn Stream<Item = Result<Bytes, BoxedError>> + Send>) -> Bytes {
hyper::body::to_bytes(hyper::Body::from(s)).await.unwrap()
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn parse_qvalue(s: &str) -> Result<u16, ()> {
"1" | "1." | "1.0" | "1.00" | "1.000" => return Ok(1000),
"0" | "0." => return Ok(0),
s if !s.starts_with("0.") => return Err(()),
_ => {},
_ => {}
};
let v = &s[2..];
let factor = match v.len() {
Expand Down Expand Up @@ -277,7 +277,7 @@ impl StreamingBodyBuilder {
where
D: From<Vec<u8>> + Send + Sync,
E: Send + Sync,
P: From<Box<dyn Stream<Item = Result<D, E>> + Send + Sync>>,
P: From<Box<dyn Stream<Item = Result<D, E>> + Send>>,
{
let (w, stream) = chunker::BodyWriter::with_chunk_size(self.chunk_size);
let mut resp = http::Response::new(stream.into());
Expand Down
19 changes: 9 additions & 10 deletions src/serving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ fn parse_modified_hdrs(
Ok((precondition_failed, not_modified))
}

fn static_body<D, E>(s: &'static str) -> Box<dyn Stream<Item = Result<D, E>> + Send + Sync>
fn static_body<D, E>(s: &'static str) -> Box<dyn Stream<Item = Result<D, E>> + Send>
where
D: 'static + Send + Sync + Buf + From<Vec<u8>> + From<&'static [u8]>,
E: 'static + Send + Sync,
D: 'static + Send + Buf + From<Vec<u8>> + From<&'static [u8]>,
E: 'static + Send,
{
Box::new(stream::once(futures::future::ok(s.as_bytes().into())))
}

fn empty_body<D, E>() -> Box<dyn Stream<Item = Result<D, E>> + Send + Sync>
fn empty_body<D, E>() -> Box<dyn Stream<Item = Result<D, E>> + Send>
where
D: 'static + Send + Sync + Buf + From<Vec<u8>> + From<&'static [u8]>,
E: 'static + Send + Sync,
D: 'static + Send + Buf + From<Vec<u8>> + From<&'static [u8]>,
E: 'static + Send,
{
Box::new(stream::empty())
}
Expand All @@ -77,7 +77,7 @@ where
/// `Expires`, `Cache-Control`, and `Vary` headers if desired.
pub fn serve<
Ent: Entity,
B: Body + From<Box<dyn Stream<Item = Result<Ent::Data, Ent::Error>> + Send + Sync>>,
B: Body + From<Box<dyn Stream<Item = Result<Ent::Data, Ent::Error>> + Send>>,
BI,
>(
entity: Ent,
Expand All @@ -97,8 +97,7 @@ pub fn serve<
next_multipart_body_chunk(state, &entity, &ranges[..], &mut part_headers[..])
});
let body = bodies.flatten();
let body: Box<dyn Stream<Item = Result<Ent::Data, Ent::Error>> + Send + Sync> =
Box::new(body);
let body: Box<dyn Stream<Item = Result<Ent::Data, Ent::Error>> + Send> = Box::new(body);
res.body(body.into()).unwrap()
}
}
Expand All @@ -118,7 +117,7 @@ enum ServeInner<B> {
fn serve_inner<
D: 'static + Send + Sync + Buf + From<Vec<u8>> + From<&'static [u8]>,
E: 'static + Send + Sync,
B: Body + From<Box<dyn Stream<Item = Result<D, E>> + Send + Sync>>,
B: Body + From<Box<dyn Stream<Item = Result<D, E>> + Send>>,
BI,
>(
ent: &dyn Entity<Error = E, Data = D>,
Expand Down