pub async fn text_with_charset(self, default_encoding: &str) -> crate::Result<String> {
        let encoding_name = self
            .content_type()
            .and_then(|mime| mime.get_param(mime::CHARSET))
            .map(|charset| charset.as_str())
            .unwrap_or(default_encoding);

        let encoding = Encoding::for_label(encoding_name.as_bytes()).unwrap_or(UTF_8);

        let bytes = self.bytes().await?;

        let (text, _, _) = encoding.decode(&bytes);

        match text {
            Cow::Owned(s) => Ok(s),
            Cow::Borrowed(s) => Ok(String::from(s)),
        }
    }
/// Get the full field data as text given a specific encoding.
///
/// This method decodes the field data with `BOM sniffing` and with malformed sequences replaced with the `REPLACEMENT CHARACTER`.
/// You can provide a default encoding for decoding the raw message, while the `charset` parameter of `Content-Type` header is still prioritized.
/// For more information about the possible encoding name, please go to [encoding_rs](https://docs.rs/encoding_rs/0.8.22/encoding_rs/) docs.
///
/// # Examples
///
/// ```
/// use multer::Multipart;
/// use bytes::Bytes;
/// use std::convert::Infallible;
/// use futures::stream::once;
///
/// # async fn run() {
/// let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
/// let stream = once(async move { Result::<Bytes, Infallible>::Ok(Bytes::from(data)) });
/// let mut multipart = Multipart::new(stream, "X-BOUNDARY");
///
/// while let Some(mut field) = multipart.next_field().await.unwrap() {
///    let content = field.text_with_charset("utf-8").await.unwrap();
///    assert_eq!(content, "abcd");
/// }
/// # }
/// # tokio::runtime::Runtime::new().unwrap().block_on(run());
/// ```
Get the full field data as text given a specific encoding.
This method decodes the field data with `BOM sniffing` and with malformed sequences replaced with the `REPLACEMENT CHARACTER`.
You can provide a default encoding for decoding the raw message, while the `charset` parameter of `Content-Type` header is still prioritized.
For more information about the possible encoding name, please go to [encoding_rs] docs.
Get the full field data as text given a specific encoding . This method decodes the field data with ` BOM sniffing ` and with malformed sequences replaced with the ` REPLACEMENT CHARACTER ` . You can provide a default encoding for decoding the raw message while the ` charset ` parameter of ` Content - Type ` header is still prioritized . For more information about the possible encoding name please go to [ encoding_rs ] docs .
pub async fn text_with_charset(self, default_encoding: &str) -> crate::Result<String> {
        let encoding_name = self
            .content_type()
            .and_then(|mime| mime.get_param(mime::CHARSET))
            .map(|charset| charset.as_str())
            .unwrap_or(default_encoding);
        let encoding = Encoding::for_label(encoding_name.as_bytes()).unwrap_or(UTF_8);
        let bytes = self.bytes().await?;
        let (text, _, _) = encoding.decode(&bytes);
        match text {
            Cow::Owned(s) => Ok(s),
            Cow::Borrowed(s) => Ok(String::from(s)),
        }
    }
pub async fn text_with_charset ( self , default_encoding : & str ) -> crate :: Result < String > { let encoding_name = self . content_type ( ) . and_then ( | mime | mime . get_param ( mime :: CHARSET ) ) . map ( | charset | charset . as_str ( ) ) . unwrap_or ( default_encoding ) ; let encoding = Encoding :: for_label ( encoding_name . as_bytes ( ) ) . unwrap_or ( UTF_8 ) ; let bytes = self . bytes ( ) . await ? ; let ( text , _ , _ ) = encoding . decode ( & bytes ) ; match text { Cow :: Owned ( s ) => Ok ( s ) , Cow :: Borrowed ( s ) => Ok ( String :: from ( s ) ) , } }
Get the full field data as text given a specific encoding.
Get the full field data as text given a specific encoding .
self
default_encoding
&str
examples
```
use multer::Multipart;
use bytes::Bytes;
use std::convert::Infallible;
use futures::stream::once.
` ` ` use multer :: Multipart ; use bytes :: Bytes ; use std :: convert :: Infallible ; use futures :: stream :: once .
async fn run() {
let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
let stream = once(async move { Result::::Ok(Bytes::from(data)) });
let mut multipart = Multipart::new(stream, "X-BOUNDARY").

while let Some(mut field) = multipart.next_field().await.unwrap() {
let content = field.text_with_charset("utf-8").await.unwrap();
assert_eq!(content, "abcd");
}
let data = " -- X - BOUNDARY \ r \ nContent - Disposition : form - data ; name = \ " my_text_field \ " \ r \ n \ r \ nabcd \ r \ n -- X - BOUNDARY -- \ r \ n " ; let stream = once ( async move { Result :::: Ok ( Bytes :: from ( data )) } ) ; let mut multipart = Multipart :: new ( stream " X - BOUNDARY " ) . while let Some ( mut field ) = multipart . next_field () . await . unwrap () { let content = field . text_with_charset ( " utf - 8 " ) . await . unwrap () ; assert_eq! ( content " abcd " ) ; }
}
None
tokio::runtime::runtime::new().unwrap().block_on(run());
None