1+ #[ cfg( feature = "alloc" ) ]
2+ use alloc:: borrow:: ToOwned ;
3+ #[ cfg( feature = "alloc" ) ]
4+ use alloc:: boxed:: Box ;
15use core:: fmt;
26use core:: ops:: { Index , IndexMut } ;
37use core:: ops:: { Range , RangeFrom , RangeFull , RangeInclusive , RangeTo , RangeToInclusive } ;
@@ -8,7 +12,7 @@ use std::error::Error;
812use std:: ffi:: CStr ;
913
1014use ascii_char:: AsciiChar ;
11- #[ cfg( feature = "std " ) ]
15+ #[ cfg( feature = "alloc " ) ]
1216use ascii_string:: AsciiString ;
1317
1418/// [`AsciiStr`] represents a byte or string slice that only contains ASCII characters.
@@ -77,7 +81,7 @@ impl AsciiStr {
7781 }
7882
7983 /// Copies the content of this `AsciiStr` into an owned `AsciiString`.
80- #[ cfg( feature = "std " ) ]
84+ #[ cfg( feature = "alloc " ) ]
8185 #[ must_use]
8286 pub fn to_ascii_string ( & self ) -> AsciiString {
8387 AsciiString :: from ( self . slice . to_vec ( ) )
@@ -283,7 +287,7 @@ impl AsciiStr {
283287 }
284288
285289 /// Returns a copy of this string where letters 'a' to 'z' are mapped to 'A' to 'Z'.
286- #[ cfg( feature = "std " ) ]
290+ #[ cfg( feature = "alloc " ) ]
287291 #[ must_use]
288292 pub fn to_ascii_uppercase ( & self ) -> AsciiString {
289293 let mut ascii_string = self . to_ascii_string ( ) ;
@@ -292,7 +296,7 @@ impl AsciiStr {
292296 }
293297
294298 /// Returns a copy of this string where letters 'A' to 'Z' are mapped to 'a' to 'z'.
295- #[ cfg( feature = "std " ) ]
299+ #[ cfg( feature = "alloc " ) ]
296300 #[ must_use]
297301 pub fn to_ascii_lowercase ( & self ) -> AsciiString {
298302 let mut ascii_string = self . to_ascii_string ( ) ;
@@ -336,7 +340,7 @@ impl_partial_eq! {str}
336340impl_partial_eq ! { [ u8 ] }
337341impl_partial_eq ! { [ AsciiChar ] }
338342
339- #[ cfg( feature = "std " ) ]
343+ #[ cfg( feature = "alloc " ) ]
340344impl ToOwned for AsciiStr {
341345 type Owned = AsciiString ;
342346
@@ -391,7 +395,7 @@ impl<'a> From<&'a mut [AsciiChar]> for &'a mut AsciiStr {
391395 unsafe { & mut * ptr }
392396 }
393397}
394- #[ cfg( feature = "std " ) ]
398+ #[ cfg( feature = "alloc " ) ]
395399impl From < Box < [ AsciiChar ] > > for Box < AsciiStr > {
396400 #[ inline]
397401 fn from ( owned : Box < [ AsciiChar ] > ) -> Box < AsciiStr > {
@@ -451,7 +455,7 @@ impl<'a> From<&'a AsciiStr> for &'a str {
451455}
452456macro_rules! widen_box {
453457 ( $wider: ty) => {
454- #[ cfg( feature = "std " ) ]
458+ #[ cfg( feature = "alloc " ) ]
455459 impl From <Box <AsciiStr >> for Box <$wider> {
456460 #[ inline]
457461 fn from( owned: Box <AsciiStr >) -> Box <$wider> {
@@ -1218,6 +1222,10 @@ impl AsAsciiStr for CStr {
12181222#[ cfg( test) ]
12191223mod tests {
12201224 use super :: { AsAsciiStr , AsAsciiStrError , AsMutAsciiStr , AsciiStr } ;
1225+ #[ cfg( feature = "alloc" ) ]
1226+ use alloc:: string:: { String , ToString } ;
1227+ #[ cfg( feature = "alloc" ) ]
1228+ use alloc:: vec:: Vec ;
12211229 use AsciiChar ;
12221230
12231231 /// Ensures that common types, `str`, `[u8]`, `AsciiStr` and their
@@ -1330,7 +1338,7 @@ mod tests {
13301338 }
13311339
13321340 #[ test]
1333- #[ cfg( feature = "std " ) ]
1341+ #[ cfg( feature = "alloc " ) ]
13341342 fn as_mut_ascii_str ( ) {
13351343 macro_rules! err { { $i: expr} => { Err ( AsAsciiStrError ( $i) ) } }
13361344 let mut s: String = "abčd" . to_string ( ) ;
@@ -1409,7 +1417,7 @@ mod tests {
14091417 }
14101418
14111419 #[ test]
1412- #[ cfg( feature = "std " ) ]
1420+ #[ cfg( feature = "alloc " ) ]
14131421 fn to_ascii_case ( ) {
14141422 let bytes = ( [ b'a' , b'@' , b'A' ] , [ b'A' , b'@' , b'a' ] ) ;
14151423 let a = bytes. 0 . as_ascii_str ( ) . unwrap ( ) ;
0 commit comments