Skip to content

Commit c840978

Browse files
committed
Move body impl, use box dyn error type
1 parent 25f9213 commit c840978

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

opentelemetry-http/src/lib.rs

+26-27
Original file line numberDiff line numberDiff line change
@@ -108,39 +108,12 @@ pub mod hyper {
108108
use http_body_util::{BodyExt, Full};
109109
use hyper::body::{Body as HttpBody, Frame};
110110
use hyper_util::client::legacy::{connect::Connect, Client};
111-
use std::convert::Infallible;
112111
use std::fmt::Debug;
113112
use std::pin::Pin;
114113
use std::task::{self, Poll};
115114
use std::time::Duration;
116115
use tokio::time;
117116

118-
pub struct Body(Full<Bytes>);
119-
120-
impl HttpBody for Body {
121-
type Data = Bytes;
122-
type Error = Infallible;
123-
124-
#[inline]
125-
fn poll_frame(
126-
self: Pin<&mut Self>,
127-
cx: &mut task::Context<'_>,
128-
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
129-
let inner_body = unsafe { self.map_unchecked_mut(|b| &mut b.0) };
130-
inner_body.poll_frame(cx)
131-
}
132-
133-
#[inline]
134-
fn is_end_stream(&self) -> bool {
135-
self.0.is_end_stream()
136-
}
137-
138-
#[inline]
139-
fn size_hint(&self) -> hyper::body::SizeHint {
140-
self.0.size_hint()
141-
}
142-
}
143-
144117
#[derive(Debug, Clone)]
145118
pub struct HyperClient<C> {
146119
inner: Client<C, Body>,
@@ -194,6 +167,32 @@ pub mod hyper {
194167
Ok(http_response.error_for_status()?)
195168
}
196169
}
170+
171+
pub struct Body(Full<Bytes>);
172+
173+
impl HttpBody for Body {
174+
type Data = Bytes;
175+
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
176+
177+
#[inline]
178+
fn poll_frame(
179+
self: Pin<&mut Self>,
180+
cx: &mut task::Context<'_>,
181+
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
182+
let inner_body = unsafe { self.map_unchecked_mut(|b| &mut b.0) };
183+
inner_body.poll_frame(cx)
184+
}
185+
186+
#[inline]
187+
fn is_end_stream(&self) -> bool {
188+
self.0.is_end_stream()
189+
}
190+
191+
#[inline]
192+
fn size_hint(&self) -> hyper::body::SizeHint {
193+
self.0.size_hint()
194+
}
195+
}
197196
}
198197

199198
/// Methods to make working with responses from the [`HttpClient`] trait easier.

0 commit comments

Comments
 (0)