1- #![ cfg_attr( not( feature = "std" ) , no_std) ]
2-
3- #[ cfg( not( feature = "std" ) ) ]
4- extern crate core as std;
5-
6- #[ cfg( not( feature = "std" ) ) ]
1+ #![ no_std]
72extern crate alloc;
83
9- use core:: convert:: Infallible ;
10- use std:: {
4+ use alloc:: {
5+ string:: { String , ToString } ,
6+ sync:: Arc ,
7+ } ;
8+ use core:: {
119 borrow:: Borrow ,
1210 cmp:: { self , Ordering } ,
11+ convert:: Infallible ,
1312 fmt, hash, iter,
1413 ops:: Deref ,
1514 str:: FromStr ,
1615} ;
1716
18- #[ cfg( not( feature = "std" ) ) ]
19- use alloc:: {
20- string:: { String , ToString } ,
21- sync:: Arc ,
22- } ;
23-
24- #[ cfg( feature = "std" ) ]
25- use std:: sync:: Arc ;
26-
2717/// A `SmolStr` is a string type that has the following properties:
2818///
2919/// * `size_of::<SmolStr>() == size_of::<String>()`
@@ -131,7 +121,7 @@ impl SmolStr {
131121 if size + len > INLINE_CAP {
132122 let ( min_remaining, _) = iter. size_hint ( ) ;
133123 let mut heap = String :: with_capacity ( size + len + min_remaining) ;
134- heap. push_str ( std :: str:: from_utf8 ( & buf[ ..len] ) . unwrap ( ) ) ;
124+ heap. push_str ( core :: str:: from_utf8 ( & buf[ ..len] ) . unwrap ( ) ) ;
135125 heap. push ( ch) ;
136126 heap. extend ( iter) ;
137127 return SmolStr ( Repr :: Heap ( heap. into_boxed_str ( ) . into ( ) ) ) ;
@@ -265,7 +255,7 @@ where
265255 let size = slice. len ( ) ;
266256 if size + len > INLINE_CAP {
267257 let mut heap = String :: with_capacity ( size + len) ;
268- heap. push_str ( std :: str:: from_utf8 ( & buf[ ..len] ) . unwrap ( ) ) ;
258+ heap. push_str ( core :: str:: from_utf8 ( & buf[ ..len] ) . unwrap ( ) ) ;
269259 heap. push_str ( & slice) ;
270260 heap. extend ( iter) ;
271261 return SmolStr ( Repr :: Heap ( heap. into_boxed_str ( ) . into ( ) ) ) ;
@@ -411,7 +401,7 @@ impl Repr {
411401 Repr :: Inline { len, buf } => {
412402 let len = * len as usize ;
413403 let buf = & buf[ ..len] ;
414- unsafe { :: std :: str:: from_utf8_unchecked ( buf) }
404+ unsafe { :: core :: str:: from_utf8_unchecked ( buf) }
415405 }
416406 Repr :: Substring { newlines, spaces } => {
417407 let newlines = * newlines;
@@ -425,9 +415,12 @@ impl Repr {
425415
426416#[ cfg( feature = "serde" ) ]
427417mod serde {
428- use super :: SmolStr ;
429- use :: serde:: de:: { Deserializer , Error , Unexpected , Visitor } ;
430- use std:: fmt;
418+ use alloc:: { string:: String , vec:: Vec } ;
419+ use core:: fmt;
420+
421+ use serde:: de:: { Deserializer , Error , Unexpected , Visitor } ;
422+
423+ use crate :: SmolStr ;
431424
432425 // https://github.com/serde-rs/serde/blob/629802f2abfd1a54a6072992888fea7ca5bc209f/serde/src/private/de.rs#L56-L125
433426 fn smol_str < ' de : ' a , ' a , D > ( deserializer : D ) -> Result < SmolStr , D :: Error >
@@ -468,7 +461,7 @@ mod serde {
468461 where
469462 E : Error ,
470463 {
471- match std :: str:: from_utf8 ( v) {
464+ match core :: str:: from_utf8 ( v) {
472465 Ok ( s) => Ok ( SmolStr :: from ( s) ) ,
473466 Err ( _) => Err ( Error :: invalid_value ( Unexpected :: Bytes ( v) , & self ) ) ,
474467 }
@@ -478,7 +471,7 @@ mod serde {
478471 where
479472 E : Error ,
480473 {
481- match std :: str:: from_utf8 ( v) {
474+ match core :: str:: from_utf8 ( v) {
482475 Ok ( s) => Ok ( SmolStr :: from ( s) ) ,
483476 Err ( _) => Err ( Error :: invalid_value ( Unexpected :: Bytes ( v) , & self ) ) ,
484477 }
0 commit comments