3838//! ```
3939
4040#![ no_std]
41+ #[ cfg( feature = "alloc" ) ]
4142extern crate alloc;
4243
44+ use core:: { fmt, mem, slice, str} ;
45+ #[ cfg( feature = "alloc" ) ]
4346use alloc:: {
4447 borrow:: { Cow , ToOwned } ,
4548 string:: String ,
4649 vec:: Vec ,
4750} ;
48- use core:: { fmt, mem, slice, str} ;
4951
5052/// Represents a set of characters or bytes in the ASCII range.
5153///
@@ -294,6 +296,7 @@ impl<'a> fmt::Display for PercentEncode<'a> {
294296 }
295297}
296298
299+ #[ cfg( feature = "alloc" ) ]
297300impl < ' a > From < PercentEncode < ' a > > for Cow < ' a , str > {
298301 fn from ( mut iter : PercentEncode < ' a > ) -> Self {
299302 match iter. next ( ) {
@@ -379,6 +382,7 @@ impl<'a> Iterator for PercentDecode<'a> {
379382 }
380383}
381384
385+ #[ cfg( feature = "alloc" ) ]
382386impl < ' a > From < PercentDecode < ' a > > for Cow < ' a , [ u8 ] > {
383387 fn from ( iter : PercentDecode < ' a > ) -> Self {
384388 match iter. if_any ( ) {
@@ -390,6 +394,7 @@ impl<'a> From<PercentDecode<'a>> for Cow<'a, [u8]> {
390394
391395impl < ' a > PercentDecode < ' a > {
392396 /// If the percent-decoding is different from the input, return it as a new bytes vector.
397+ #[ cfg( feature = "alloc" ) ]
393398 fn if_any ( & self ) -> Option < Vec < u8 > > {
394399 let mut bytes_iter = self . bytes . clone ( ) ;
395400 while bytes_iter. any ( |& b| b == b'%' ) {
@@ -409,6 +414,7 @@ impl<'a> PercentDecode<'a> {
409414 /// Decode the result of percent-decoding as UTF-8.
410415 ///
411416 /// This is return `Err` when the percent-decoded bytes are not well-formed in UTF-8.
417+ #[ cfg( feature = "alloc" ) ]
412418 pub fn decode_utf8 ( self ) -> Result < Cow < ' a , str > , str:: Utf8Error > {
413419 match self . clone ( ) . into ( ) {
414420 Cow :: Borrowed ( bytes) => match str:: from_utf8 ( bytes) {
@@ -426,11 +432,13 @@ impl<'a> PercentDecode<'a> {
426432 ///
427433 /// Invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD,
428434 /// the replacement character.
435+ #[ cfg( feature = "alloc" ) ]
429436 pub fn decode_utf8_lossy ( self ) -> Cow < ' a , str > {
430437 decode_utf8_lossy ( self . clone ( ) . into ( ) )
431438 }
432439}
433440
441+ #[ cfg( feature = "alloc" ) ]
434442fn decode_utf8_lossy ( input : Cow < ' _ , [ u8 ] > ) -> Cow < ' _ , str > {
435443 // Note: This function is duplicated in `form_urlencoded/src/query_encoding.rs`.
436444 match input {
0 commit comments