pub struct AsyncRequestBody<'a>(_);
Available on crate feature async only.
Expand description

异步 HTTP 请求体

Implementations§

通过异步输入流的可变引用创建异步 HTTP 请求体

Examples found in repository?
src/request.rs (line 945)
944
945
946
            fn from(body: &'a mut AsyncRequestBody<'_>) -> Self {
                Self::from_referenced_reader(body, body.size())
            }

通过二进制数据的引用创建异步 HTTP 请求体

Examples found in repository?
src/request.rs (line 952)
951
952
953
954
955
956
957
958
959
960
            fn from(body: &'a [u8]) -> Self {
                Self::from_referenced_bytes(body)
            }
        }

        impl<'a> From<&'a str> for AsyncRequestBody<'a> {
            #[inline]
            fn from(body: &'a str) -> Self {
                Self::from_referenced_bytes(body.as_bytes())
            }

通过异步输入流创建异步 HTTP 请求体

通过二进制数据创建异步 HTTP 请求体

Examples found in repository?
src/request.rs (line 906)
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
            fn default() -> Self {
                Self::from_bytes(Default::default())
            }
        }

        impl AsyncRead for AsyncRequestBody<'_> {
            fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll<IoResult<usize>> {
                match &mut self.as_mut().0 {
                    AsyncRequestBodyInner::ReaderRef { reader, .. } => {
                        pin!(reader);
                        reader.poll_read(cx, buf)
                    }
                    AsyncRequestBodyInner::BytesRef(bytes) => {
                        pin!(bytes);
                        bytes.poll_read(cx, buf)
                    }
                    AsyncRequestBodyInner::Owned(owned) => {
                        pin!(owned);
                        owned.poll_read(cx, buf)
                    }
                }
            }
        }

        impl AsyncReset for AsyncRequestBody<'_> {
            #[inline]
            fn reset(&mut self) -> BoxFuture<IoResult<()>> {
                Box::pin(async move {
                    match &mut self.0 {
                        AsyncRequestBodyInner::ReaderRef { reader, .. } => reader.reset().await,
                        AsyncRequestBodyInner::BytesRef(bytes) => bytes.reset().await,
                        AsyncRequestBodyInner::Owned(owned) => owned.reset().await,
                    }
                })
            }
        }

        impl<'a> From<&'a mut AsyncRequestBody<'_>> for AsyncRequestBody<'a> {
            #[inline]
            fn from(body: &'a mut AsyncRequestBody<'_>) -> Self {
                Self::from_referenced_reader(body, body.size())
            }
        }

        impl<'a> From<&'a [u8]> for AsyncRequestBody<'a> {
            #[inline]
            fn from(body: &'a [u8]) -> Self {
                Self::from_referenced_bytes(body)
            }
        }

        impl<'a> From<&'a str> for AsyncRequestBody<'a> {
            #[inline]
            fn from(body: &'a str) -> Self {
                Self::from_referenced_bytes(body.as_bytes())
            }
        }

        impl From<Vec<u8>> for AsyncRequestBody<'_> {
            #[inline]
            fn from(body: Vec<u8>) -> Self {
                Self::from_bytes(body)
            }
        }

        impl From<String> for AsyncRequestBody<'_> {
            #[inline]
            fn from(body: String) -> Self {
                Self::from_bytes(body.into_bytes())
            }

获取请求体大小

单位为字节

Examples found in repository?
src/request.rs (line 945)
944
945
946
            fn from(body: &'a mut AsyncRequestBody<'_>) -> Self {
                Self::from_referenced_reader(body, body.size())
            }

Trait Implementations§

Attempt to read from the AsyncRead into buf. Read more
Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Available on crate feature async only.
异步重置输入流 Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Reads some bytes from the byte stream. Read more
Like read(), except it reads into a slice of buffers. Read more
Reads the entire contents and appends them to a Vec. Read more
Reads the entire contents and appends them to a String. Read more
Reads the exact number of bytes required to fill buf. Read more
Creates an adapter which will read at most limit bytes from it. Read more
Converts this AsyncRead into a [Stream] of bytes. Read more
Creates an adapter which will chain this stream with another. Read more
Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.