From f73c13c87c8131c89f05480e27befd3c9dddcdd6 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Sat, 8 May 2021 11:38:22 +0200 Subject: [PATCH] Correctly override `size_hint` and `is_end_stream` for `Empty` I noticed this while working on https://github.com/hyperium/tonic/pull/622 as it broke some interop tests. --- CHANGELOG.md | 2 +- src/empty.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a41e51..83a2cf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Unreleased -Nothing. +- Correctly override `Body::size_hint` and `Body::is_end_stream` for `Empty`. # 0.4.1 (March 18, 2021) diff --git a/src/empty.rs b/src/empty.rs index b12bf4c..7d63ceb 100644 --- a/src/empty.rs +++ b/src/empty.rs @@ -1,4 +1,4 @@ -use super::Body; +use super::{Body, SizeHint}; use bytes::Buf; use http::HeaderMap; use std::{ @@ -40,6 +40,14 @@ impl Body for Empty { ) -> Poll, Self::Error>> { Poll::Ready(Ok(None)) } + + fn is_end_stream(&self) -> bool { + true + } + + fn size_hint(&self) -> SizeHint { + SizeHint::with_exact(0) + } } impl fmt::Debug for Empty {