3737//! assert_eq!(utf8_percent_encode("foo <bar>", FRAGMENT).to_string(), "foo%20%3Cbar%3E");
3838//! ```
3939
40- #![ cfg_attr( not( feature = "std" ) , no_std) ]
41-
42- #[ cfg( not( feature = "std" ) ) ]
40+ #![ no_std]
41+ #[ cfg( feature = "alloc" ) ]
42+ extern crate alloc;
43+
44+ #[ cfg( feature = "alloc" ) ]
45+ use alloc:: {
46+ borrow:: { Cow , ToOwned } ,
47+ string:: String ,
48+ vec:: Vec ,
49+ } ;
4350use core:: { fmt, mem, slice, str} ;
44- #[ cfg( feature = "std" ) ]
45- use std:: borrow:: Cow ;
46- #[ cfg( feature = "std" ) ]
47- use std:: { fmt, mem, slice, str} ;
4851
4952/// Represents a set of characters or bytes in the ASCII range.
5053///
@@ -293,7 +296,7 @@ impl<'a> fmt::Display for PercentEncode<'a> {
293296 }
294297}
295298
296- #[ cfg( feature = "std " ) ]
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 ( ) {
@@ -332,18 +335,13 @@ pub fn percent_decode_str(input: &str) -> PercentDecode<'_> {
332335/// * Implements `Iterator<Item = u8>` and therefore has a `.collect::<Vec<u8>>()` method,
333336/// * Has `decode_utf8()` and `decode_utf8_lossy()` methods.
334337///
335- #[ cfg_attr(
336- feature = "std" ,
337- doc = r##"
338- # Examples
339-
340- ```
341- use percent_encoding::percent_decode;
342-
343- assert_eq!(percent_decode(b"foo%20bar%3f").decode_utf8().unwrap(), "foo bar?");
344- ```
345- "##
346- ) ]
338+ /// # Examples
339+ ///
340+ /// ```
341+ /// use percent_encoding::percent_decode;
342+ ///
343+ /// assert_eq!(percent_decode(b"foo%20bar%3f").decode_utf8().unwrap(), "foo bar?");
344+ /// ```
347345#[ inline]
348346pub fn percent_decode ( input : & [ u8 ] ) -> PercentDecode < ' _ > {
349347 PercentDecode {
@@ -384,7 +382,7 @@ impl<'a> Iterator for PercentDecode<'a> {
384382 }
385383}
386384
387- #[ cfg( feature = "std " ) ]
385+ #[ cfg( feature = "alloc " ) ]
388386impl < ' a > From < PercentDecode < ' a > > for Cow < ' a , [ u8 ] > {
389387 fn from ( iter : PercentDecode < ' a > ) -> Self {
390388 match iter. if_any ( ) {
@@ -396,7 +394,7 @@ impl<'a> From<PercentDecode<'a>> for Cow<'a, [u8]> {
396394
397395impl < ' a > PercentDecode < ' a > {
398396 /// If the percent-decoding is different from the input, return it as a new bytes vector.
399- #[ cfg( feature = "std " ) ]
397+ #[ cfg( feature = "alloc " ) ]
400398 fn if_any ( & self ) -> Option < Vec < u8 > > {
401399 let mut bytes_iter = self . bytes . clone ( ) ;
402400 while bytes_iter. any ( |& b| b == b'%' ) {
@@ -416,7 +414,7 @@ impl<'a> PercentDecode<'a> {
416414 /// Decode the result of percent-decoding as UTF-8.
417415 ///
418416 /// This is return `Err` when the percent-decoded bytes are not well-formed in UTF-8.
419- #[ cfg( feature = "std " ) ]
417+ #[ cfg( feature = "alloc " ) ]
420418 pub fn decode_utf8 ( self ) -> Result < Cow < ' a , str > , str:: Utf8Error > {
421419 match self . clone ( ) . into ( ) {
422420 Cow :: Borrowed ( bytes) => match str:: from_utf8 ( bytes) {
@@ -434,13 +432,13 @@ impl<'a> PercentDecode<'a> {
434432 ///
435433 /// Invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD,
436434 /// the replacement character.
437- #[ cfg( feature = "std " ) ]
435+ #[ cfg( feature = "alloc " ) ]
438436 pub fn decode_utf8_lossy ( self ) -> Cow < ' a , str > {
439437 decode_utf8_lossy ( self . clone ( ) . into ( ) )
440438 }
441439}
442440
443- #[ cfg( feature = "std " ) ]
441+ #[ cfg( feature = "alloc " ) ]
444442fn decode_utf8_lossy ( input : Cow < ' _ , [ u8 ] > ) -> Cow < ' _ , str > {
445443 // Note: This function is duplicated in `form_urlencoded/src/query_encoding.rs`.
446444 match input {
0 commit comments