38
38
//! ```
39
39
40
40
#![ no_std]
41
+ #[ cfg( feature = "alloc" ) ]
41
42
extern crate alloc;
42
43
44
+ use core:: { fmt, mem, slice, str} ;
45
+ #[ cfg( feature = "alloc" ) ]
43
46
use alloc:: {
44
47
borrow:: { Cow , ToOwned } ,
45
48
string:: String ,
46
49
vec:: Vec ,
47
50
} ;
48
- use core:: { fmt, mem, slice, str} ;
49
51
50
52
/// Represents a set of characters or bytes in the ASCII range.
51
53
///
@@ -294,6 +296,7 @@ impl<'a> fmt::Display for PercentEncode<'a> {
294
296
}
295
297
}
296
298
299
+ #[ cfg( feature = "alloc" ) ]
297
300
impl < ' a > From < PercentEncode < ' a > > for Cow < ' a , str > {
298
301
fn from ( mut iter : PercentEncode < ' a > ) -> Self {
299
302
match iter. next ( ) {
@@ -379,6 +382,7 @@ impl<'a> Iterator for PercentDecode<'a> {
379
382
}
380
383
}
381
384
385
+ #[ cfg( feature = "alloc" ) ]
382
386
impl < ' a > From < PercentDecode < ' a > > for Cow < ' a , [ u8 ] > {
383
387
fn from ( iter : PercentDecode < ' a > ) -> Self {
384
388
match iter. if_any ( ) {
@@ -390,6 +394,7 @@ impl<'a> From<PercentDecode<'a>> for Cow<'a, [u8]> {
390
394
391
395
impl < ' a > PercentDecode < ' a > {
392
396
/// If the percent-decoding is different from the input, return it as a new bytes vector.
397
+ #[ cfg( feature = "alloc" ) ]
393
398
fn if_any ( & self ) -> Option < Vec < u8 > > {
394
399
let mut bytes_iter = self . bytes . clone ( ) ;
395
400
while bytes_iter. any ( |& b| b == b'%' ) {
@@ -409,6 +414,7 @@ impl<'a> PercentDecode<'a> {
409
414
/// Decode the result of percent-decoding as UTF-8.
410
415
///
411
416
/// This is return `Err` when the percent-decoded bytes are not well-formed in UTF-8.
417
+ #[ cfg( feature = "alloc" ) ]
412
418
pub fn decode_utf8 ( self ) -> Result < Cow < ' a , str > , str:: Utf8Error > {
413
419
match self . clone ( ) . into ( ) {
414
420
Cow :: Borrowed ( bytes) => match str:: from_utf8 ( bytes) {
@@ -426,11 +432,13 @@ impl<'a> PercentDecode<'a> {
426
432
///
427
433
/// Invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD,
428
434
/// the replacement character.
435
+ #[ cfg( feature = "alloc" ) ]
429
436
pub fn decode_utf8_lossy ( self ) -> Cow < ' a , str > {
430
437
decode_utf8_lossy ( self . clone ( ) . into ( ) )
431
438
}
432
439
}
433
440
441
+ #[ cfg( feature = "alloc" ) ]
434
442
fn decode_utf8_lossy ( input : Cow < ' _ , [ u8 ] > ) -> Cow < ' _ , str > {
435
443
// Note: This function is duplicated in `form_urlencoded/src/query_encoding.rs`.
436
444
match input {
0 commit comments