5454#![ deny( missing_docs) ]
5555#![ deny( rust_2018_compatibility) ]
5656#![ deny( rust_2018_idioms) ]
57+ // Note: Even though we declare the crate as `no_std`, by default `std` feature
58+ // is enabled which enables serde’s `std` feature which makes our dependency
59+ // non-`no_std`. This `no_std` declaration only makes sure that our code
60+ // doesn’t depend on `std` directly (except for tests).
61+ #![ no_std]
62+
63+ extern crate alloc;
64+ #[ cfg( test) ]
65+ extern crate std;
5766
5867pub mod de;
5968pub mod ser;
@@ -65,7 +74,11 @@ pub use self::ser::{to_string, to_vec};
6574
6675#[ cfg( test) ]
6776mod test {
68- use std:: collections:: BTreeMap ;
77+ use alloc:: borrow:: ToOwned ;
78+ use alloc:: collections:: BTreeMap ;
79+ use alloc:: string:: { String , ToString } ;
80+ use alloc:: vec;
81+ use alloc:: vec:: Vec ;
6982
7083 use super :: * ;
7184 use serde_derive:: { Deserialize , Serialize } ;
@@ -104,7 +117,7 @@ mod test {
104117 fn can_serde ( ) {
105118 let min = Item {
106119 model : Model :: Comment ,
107- title : "" . to_string ( ) ,
120+ title : String :: new ( ) ,
108121 content : None ,
109122 list : vec ! [ ] ,
110123 published : false ,
@@ -121,12 +134,12 @@ mod test {
121134 } ,
122135 title : "Nice message" . to_string ( ) ,
123136 content : Some ( "Happy \" blogging\" 👏\n \n \t Cheers, I'm out\0 \0 \0 " . to_string ( ) ) ,
124- list : vec ! [ 0 , 1 , 2 , 3 , 42 , 154841 , std :: u32 :: MAX ] ,
137+ list : vec ! [ 0 , 1 , 2 , 3 , 42 , 154841 , u32 :: MAX ] ,
125138 published : true ,
126139 comments : vec ! [ CommentId ( 2 ) , CommentId ( 700 ) ] ,
127140 stats : Stats {
128- views : std :: u64:: MAX ,
129- score : std :: i64:: MIN ,
141+ views : u64:: MAX ,
142+ score : i64:: MIN ,
130143 } ,
131144 balances,
132145 } ;
0 commit comments