@@ -6,14 +6,15 @@ mod map;
6
6
mod seq;
7
7
mod unescape;
8
8
9
+ use alloc:: string:: String ;
10
+
9
11
pub use errors:: { Error , Result } ;
10
12
11
13
use serde:: de:: { self , Visitor } ;
12
14
13
15
use self :: enum_:: { StructVariantAccess , UnitVariantAccess } ;
14
16
use self :: map:: MapAccess ;
15
17
use self :: seq:: SeqAccess ;
16
- use std:: str:: from_utf8;
17
18
18
19
/// Deserializer will parse serde-json-wasm flavored JSON into a
19
20
/// serde-annotated struct
@@ -126,7 +127,7 @@ impl<'a> Deserializer<'a> {
126
127
) ?) )
127
128
} else {
128
129
Ok ( StringLike :: Borrowed (
129
- from_utf8 ( & self . slice [ start..end] )
130
+ core :: str :: from_utf8 ( & self . slice [ start..end] )
130
131
. map_err ( |_| Error :: InvalidUnicodeCodePoint ) ?,
131
132
) )
132
133
} ;
@@ -687,6 +688,11 @@ where
687
688
#[ cfg( test) ]
688
689
mod tests {
689
690
use super :: from_str;
691
+
692
+ use alloc:: string:: { String , ToString } ;
693
+ use alloc:: vec;
694
+ use alloc:: vec:: Vec ;
695
+
690
696
use serde_derive:: { Deserialize , Serialize } ;
691
697
692
698
#[ derive( Debug , Deserialize , PartialEq ) ]
@@ -947,7 +953,7 @@ mod tests {
947
953
assert_eq ! (
948
954
from_str( r#"{ "description": "An ambient temperature sensor" }"# ) ,
949
955
Ok ( Property {
950
- description: Some ( "An ambient temperature sensor" . to_string ( ) ) ,
956
+ description: Some ( "An ambient temperature sensor" . into ( ) ) ,
951
957
} )
952
958
) ;
953
959
@@ -1036,7 +1042,7 @@ mod tests {
1036
1042
}
1037
1043
1038
1044
let expected = Users {
1039
- users : vec ! [ "joe" . to_string ( ) , "alice" . to_string ( ) ] ,
1045
+ users : vec ! [ "joe" . into ( ) , "alice" . into ( ) ] ,
1040
1046
pagination : Pagination {
1041
1047
offset : 100 ,
1042
1048
limit : 20 ,
@@ -1116,7 +1122,7 @@ mod tests {
1116
1122
}
1117
1123
1118
1124
let element: Address = from_str ( r#""johnny""# ) . unwrap ( ) ;
1119
- assert_eq ! ( element, Address ( "johnny" . to_string ( ) ) ) ;
1125
+ assert_eq ! ( element, Address ( "johnny" . into ( ) ) ) ;
1120
1126
1121
1127
let element: CommentId = from_str ( r#"5464813"# ) . unwrap ( ) ;
1122
1128
assert_eq ! ( element, CommentId ( 5464813 ) ) ;
@@ -1125,101 +1131,101 @@ mod tests {
1125
1131
assert_eq ! (
1126
1132
element,
1127
1133
NewtypeDemo {
1128
- address: Address ( "johnny" . to_string ( ) ) ,
1134
+ address: Address ( "johnny" . into ( ) ) ,
1129
1135
comment: CommentId ( 9897 ) ,
1130
1136
}
1131
1137
) ;
1132
1138
}
1133
1139
1134
1140
#[ test]
1135
1141
fn numbered_key_maps ( ) {
1136
- use std :: collections:: BTreeMap ;
1142
+ use alloc :: collections:: BTreeMap ;
1137
1143
1138
1144
// u8
1139
1145
let mut ranking: BTreeMap < u8 , String > = BTreeMap :: new ( ) ;
1140
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1141
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1146
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1147
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1142
1148
assert_eq ! (
1143
1149
from_str:: <BTreeMap <u8 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1144
1150
ranking
1145
1151
) ;
1146
1152
1147
1153
// u16
1148
1154
let mut ranking: BTreeMap < u16 , String > = BTreeMap :: new ( ) ;
1149
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1150
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1155
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1156
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1151
1157
assert_eq ! (
1152
1158
from_str:: <BTreeMap <u16 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1153
1159
ranking
1154
1160
) ;
1155
1161
1156
1162
// u32
1157
1163
let mut ranking: BTreeMap < u32 , String > = BTreeMap :: new ( ) ;
1158
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1159
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1164
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1165
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1160
1166
assert_eq ! (
1161
1167
from_str:: <BTreeMap <u32 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1162
1168
ranking
1163
1169
) ;
1164
1170
1165
1171
// u64
1166
1172
let mut ranking: BTreeMap < u64 , String > = BTreeMap :: new ( ) ;
1167
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1168
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1173
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1174
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1169
1175
assert_eq ! (
1170
1176
from_str:: <BTreeMap <u64 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1171
1177
ranking
1172
1178
) ;
1173
1179
1174
1180
// u128
1175
1181
let mut ranking: BTreeMap < u128 , String > = BTreeMap :: new ( ) ;
1176
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1177
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1182
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1183
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1178
1184
assert_eq ! (
1179
1185
from_str:: <BTreeMap <u128 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1180
1186
ranking
1181
1187
) ;
1182
1188
1183
1189
// i8
1184
1190
let mut ranking: BTreeMap < i8 , String > = BTreeMap :: new ( ) ;
1185
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1186
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1191
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1192
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1187
1193
assert_eq ! (
1188
1194
from_str:: <BTreeMap <i8 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1189
1195
ranking
1190
1196
) ;
1191
1197
1192
1198
// i16
1193
1199
let mut ranking: BTreeMap < i16 , String > = BTreeMap :: new ( ) ;
1194
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1195
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1200
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1201
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1196
1202
assert_eq ! (
1197
1203
from_str:: <BTreeMap <i16 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1198
1204
ranking
1199
1205
) ;
1200
1206
1201
1207
// i32
1202
1208
let mut ranking: BTreeMap < i32 , String > = BTreeMap :: new ( ) ;
1203
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1204
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1209
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1210
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1205
1211
assert_eq ! (
1206
1212
from_str:: <BTreeMap <i32 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1207
1213
ranking
1208
1214
) ;
1209
1215
1210
1216
// i64
1211
1217
let mut ranking: BTreeMap < i64 , String > = BTreeMap :: new ( ) ;
1212
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1213
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1218
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1219
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1214
1220
assert_eq ! (
1215
1221
from_str:: <BTreeMap <i64 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1216
1222
ranking
1217
1223
) ;
1218
1224
1219
1225
// i128
1220
1226
let mut ranking: BTreeMap < i128 , String > = BTreeMap :: new ( ) ;
1221
- ranking. insert ( 1 , "Elon" . to_string ( ) ) ;
1222
- ranking. insert ( 2 , "Bazos" . to_string ( ) ) ;
1227
+ ranking. insert ( 1 , "Elon" . into ( ) ) ;
1228
+ ranking. insert ( 2 , "Bazos" . into ( ) ) ;
1223
1229
assert_eq ! (
1224
1230
from_str:: <BTreeMap <i128 , String >>( r#"{"1": "Elon", "2": "Bazos"}"# ) . unwrap( ) ,
1225
1231
ranking
@@ -1250,12 +1256,7 @@ mod tests {
1250
1256
}"# ,
1251
1257
)
1252
1258
. expect ( "simple" ) ;
1253
- assert_eq ! (
1254
- m,
1255
- Msg {
1256
- name: "one" . to_string( )
1257
- }
1258
- ) ;
1259
+ assert_eq ! ( m, Msg { name: "one" . into( ) } ) ;
1259
1260
1260
1261
let o: OptIn = from_str (
1261
1262
r#"{
@@ -1266,7 +1267,7 @@ mod tests {
1266
1267
assert_eq ! (
1267
1268
o,
1268
1269
OptIn {
1269
- name: Some ( "two" . to_string ( ) )
1270
+ name: Some ( "two" . into ( ) )
1270
1271
}
1271
1272
) ;
1272
1273
@@ -1280,10 +1281,8 @@ mod tests {
1280
1281
assert_eq ! (
1281
1282
res,
1282
1283
Response {
1283
- log: Some ( "my log" . to_string( ) ) ,
1284
- messages: vec![ Msg {
1285
- name: "one" . to_string( )
1286
- } ] ,
1284
+ log: Some ( "my log" . into( ) ) ,
1285
+ messages: vec![ Msg { name: "one" . into( ) } ] ,
1287
1286
}
1288
1287
) ;
1289
1288
@@ -1333,10 +1332,10 @@ mod tests {
1333
1332
assert_eq ! (
1334
1333
res,
1335
1334
MyResult :: Ok ( Response {
1336
- log: Some ( "hello" . to_string ( ) ) ,
1335
+ log: Some ( "hello" . into ( ) ) ,
1337
1336
messages: vec![ Msg {
1338
- name: "fred" . to_string ( ) ,
1339
- amount: Some ( "15" . to_string ( ) )
1337
+ name: "fred" . into ( ) ,
1338
+ amount: Some ( "15" . into ( ) )
1340
1339
} ]
1341
1340
} )
1342
1341
) ;
@@ -1353,7 +1352,7 @@ mod tests {
1353
1352
assert_eq ! (
1354
1353
res,
1355
1354
MyResult :: Ok ( Response {
1356
- log: Some ( "hello" . to_string ( ) ) ,
1355
+ log: Some ( "hello" . into ( ) ) ,
1357
1356
messages: Vec :: new( )
1358
1357
} )
1359
1358
) ;
@@ -1433,21 +1432,21 @@ mod tests {
1433
1432
properties: Properties {
1434
1433
temperature: Property {
1435
1434
ty: Type :: Number ,
1436
- unit: Some ( "celsius" . to_string ( ) ) ,
1437
- description: Some ( "An ambient temperature sensor" . to_string ( ) ) ,
1438
- href: "/properties/temperature" . to_string ( ) ,
1435
+ unit: Some ( "celsius" . into ( ) ) ,
1436
+ description: Some ( "An ambient temperature sensor" . into ( ) ) ,
1437
+ href: "/properties/temperature" . into ( ) ,
1439
1438
} ,
1440
1439
humidity: Property {
1441
1440
ty: Type :: Number ,
1442
- unit: Some ( "percent" . to_string ( ) ) ,
1441
+ unit: Some ( "percent" . into ( ) ) ,
1443
1442
description: None ,
1444
- href: "/properties/humidity" . to_string ( ) ,
1443
+ href: "/properties/humidity" . into ( ) ,
1445
1444
} ,
1446
1445
led: Property {
1447
1446
ty: Type :: Boolean ,
1448
1447
unit: None ,
1449
- description: Some ( "A red LED" . to_string ( ) ) ,
1450
- href: "/properties/led" . to_string ( ) ,
1448
+ description: Some ( "A red LED" . into ( ) ) ,
1449
+ href: "/properties/led" . into ( ) ,
1451
1450
} ,
1452
1451
} ,
1453
1452
ty: Type :: Thing ,
0 commit comments