Fix compile error when target is wasm and multipart feature is enabled. (#1296)

This commit is contained in:
Saruniks
2021-07-01 05:13:42 +03:00
committed by GitHub
parent bccefe7486
commit e6a1a09f09
2 changed files with 15 additions and 9 deletions

View File

@@ -17,7 +17,6 @@ pub struct Body {
inner: Inner, inner: Inner,
} }
#[derive(Clone)]
enum Inner { enum Inner {
Bytes(Bytes), Bytes(Bytes),
#[cfg(feature = "multipart")] #[cfg(feature = "multipart")]
@@ -58,9 +57,13 @@ impl Body {
} }
} }
pub(crate) fn clone(&self) -> Body { pub(crate) fn try_clone(&self) -> Option<Body> {
Self { match &self.inner {
inner: self.inner.clone(), Inner::Bytes(bytes) => Some(Self {
inner: Inner::Bytes(bytes.clone()),
}),
#[cfg(feature = "multipart")]
Inner::Multipart(_) => None,
} }
} }
} }

View File

@@ -92,14 +92,18 @@ impl Request {
/// Attempts to clone the `Request`. /// Attempts to clone the `Request`.
/// ///
/// None is returned if a body is which can not be cloned. This method /// None is returned if a body is which can not be cloned.
/// currently always returns `Some`, but that may change in the future.
pub fn try_clone(&self) -> Option<Request> { pub fn try_clone(&self) -> Option<Request> {
let body = match self.body.as_ref() {
Some(ref body) => Some(body.try_clone()?),
None => None,
};
Some(Self { Some(Self {
method: self.method.clone(), method: self.method.clone(),
url: self.url.clone(), url: self.url.clone(),
headers: self.headers.clone(), headers: self.headers.clone(),
body: self.body.as_ref().map(|body| body.clone()), body,
cors: self.cors, cors: self.cors,
credentials: self.credentials.clone(), credentials: self.credentials.clone(),
}) })
@@ -353,8 +357,7 @@ impl RequestBuilder {
/// Attempt to clone the RequestBuilder. /// Attempt to clone the RequestBuilder.
/// ///
/// `None` is returned if the RequestBuilder can not be cloned. This method /// `None` is returned if the RequestBuilder can not be cloned.
/// currently always returns `Some`, but that may change in the future.
/// ///
/// # Examples /// # Examples
/// ///