@@ -11,6 +11,11 @@ pub struct BoxBody<D, E> {
1111 inner : Pin < Box < dyn Body < Data = D , Error = E > + Send + Sync + ' static > > ,
1212}
1313
14+ /// A boxed [`Body`] trait object that is !Sync.
15+ pub struct UnsyncBoxBody < D , E > {
16+ inner : Pin < Box < dyn Body < Data = D , Error = E > + Send + ' static > > ,
17+ }
18+
1419impl < D , E > BoxBody < D , E > {
1520 /// Create a new `BoxBody`.
1621 pub fn new < B > ( body : B ) -> Self
6873 BoxBody :: new ( crate :: Empty :: new ( ) . map_err ( |err| match err { } ) )
6974 }
7075}
76+
77+ // === UnsyncBoxBody ===
78+ impl < D , E > UnsyncBoxBody < D , E > {
79+ /// Create a new `BoxBody`.
80+ pub fn new < B > ( body : B ) -> Self
81+ where
82+ B : Body < Data = D , Error = E > + Send + ' static ,
83+ D : Buf ,
84+ {
85+ Self {
86+ inner : Box :: pin ( body) ,
87+ }
88+ }
89+ }
90+
91+ impl < D , E > fmt:: Debug for UnsyncBoxBody < D , E > {
92+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
93+ f. debug_struct ( "UnsyncBoxBody" ) . finish ( )
94+ }
95+ }
96+
97+ impl < D , E > Body for UnsyncBoxBody < D , E >
98+ where
99+ D : Buf ,
100+ {
101+ type Data = D ;
102+ type Error = E ;
103+
104+ fn poll_data (
105+ mut self : Pin < & mut Self > ,
106+ cx : & mut Context < ' _ > ,
107+ ) -> Poll < Option < Result < Self :: Data , Self :: Error > > > {
108+ self . inner . as_mut ( ) . poll_data ( cx)
109+ }
110+
111+ fn poll_trailers (
112+ mut self : Pin < & mut Self > ,
113+ cx : & mut Context < ' _ > ,
114+ ) -> Poll < Result < Option < http:: HeaderMap > , Self :: Error > > {
115+ self . inner . as_mut ( ) . poll_trailers ( cx)
116+ }
117+
118+ fn is_end_stream ( & self ) -> bool {
119+ self . inner . is_end_stream ( )
120+ }
121+
122+ fn size_hint ( & self ) -> crate :: SizeHint {
123+ self . inner . size_hint ( )
124+ }
125+ }
126+
127+ impl < D , E > Default for UnsyncBoxBody < D , E >
128+ where
129+ D : Buf + ' static ,
130+ {
131+ fn default ( ) -> Self {
132+ UnsyncBoxBody :: new ( crate :: Empty :: new ( ) . map_err ( |err| match err { } ) )
133+ }
134+ }
0 commit comments