-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasm): add wasm32-wasip2 stable support
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com> cleanup extraneous comment Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com> feat: give back incoming body too Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
- Loading branch information
1 parent
344179b
commit 2cad7e9
Showing
8 changed files
with
1,012 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
use bytes::Bytes; | ||
use std::{borrow::Cow, fmt}; | ||
|
||
/// The body of a [`super::Request`]. | ||
pub struct Body { | ||
inner: Inner, | ||
} | ||
|
||
enum Inner { | ||
Single(Single), | ||
} | ||
|
||
#[derive(Clone)] | ||
pub(crate) enum Single { | ||
Bytes(Bytes), | ||
Text(Cow<'static, str>), | ||
} | ||
|
||
impl Single { | ||
fn as_bytes(&self) -> &[u8] { | ||
match self { | ||
Single::Bytes(bytes) => bytes.as_ref(), | ||
Single::Text(text) => text.as_bytes(), | ||
} | ||
} | ||
|
||
fn is_empty(&self) -> bool { | ||
match self { | ||
Single::Bytes(bytes) => bytes.is_empty(), | ||
Single::Text(text) => text.is_empty(), | ||
} | ||
} | ||
} | ||
|
||
impl Body { | ||
/// Returns a reference to the internal data of the `Body`. | ||
/// | ||
/// `None` is returned, if the underlying data is a multipart form. | ||
#[inline] | ||
pub fn as_bytes(&self) -> Option<&[u8]> { | ||
match &self.inner { | ||
Inner::Single(single) => Some(single.as_bytes()), | ||
} | ||
} | ||
|
||
#[allow(unused)] | ||
pub(crate) fn is_empty(&self) -> bool { | ||
match &self.inner { | ||
Inner::Single(single) => single.is_empty(), | ||
} | ||
} | ||
|
||
pub(crate) fn try_clone(&self) -> Option<Body> { | ||
match &self.inner { | ||
Inner::Single(single) => Some(Self { | ||
inner: Inner::Single(single.clone()), | ||
}), | ||
} | ||
} | ||
} | ||
|
||
impl From<Bytes> for Body { | ||
#[inline] | ||
fn from(bytes: Bytes) -> Body { | ||
Body { | ||
inner: Inner::Single(Single::Bytes(bytes)), | ||
} | ||
} | ||
} | ||
|
||
impl From<Vec<u8>> for Body { | ||
#[inline] | ||
fn from(vec: Vec<u8>) -> Body { | ||
Body { | ||
inner: Inner::Single(Single::Bytes(vec.into())), | ||
} | ||
} | ||
} | ||
|
||
impl From<&'static [u8]> for Body { | ||
#[inline] | ||
fn from(s: &'static [u8]) -> Body { | ||
Body { | ||
inner: Inner::Single(Single::Bytes(Bytes::from_static(s))), | ||
} | ||
} | ||
} | ||
|
||
impl From<String> for Body { | ||
#[inline] | ||
fn from(s: String) -> Body { | ||
Body { | ||
inner: Inner::Single(Single::Text(s.into())), | ||
} | ||
} | ||
} | ||
|
||
impl From<&'static str> for Body { | ||
#[inline] | ||
fn from(s: &'static str) -> Body { | ||
Body { | ||
inner: Inner::Single(Single::Text(s.into())), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Debug for Body { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_struct("Body").finish() | ||
} | ||
} |
Oops, something went wrong.