@@ -1219,6 +1219,178 @@ impl FromReflect for Cow<'static, str> {
1219
1219
}
1220
1220
}
1221
1221
1222
+ impl < T : PathOnly > PathOnly for [ T ] where [ T ] : ToOwned { }
1223
+
1224
+ impl < T : TypePath > TypePath for [ T ]
1225
+ where
1226
+ [ T ] : ToOwned ,
1227
+ {
1228
+ fn type_path ( ) -> & ' static str {
1229
+ static CELL : GenericTypePathCell = GenericTypePathCell :: new ( ) ;
1230
+ CELL . get_or_insert :: < Self , _ > ( || format ! ( "[{}]" , <T >:: type_path( ) ) )
1231
+ }
1232
+
1233
+ fn short_type_path ( ) -> & ' static str {
1234
+ static CELL : GenericTypePathCell = GenericTypePathCell :: new ( ) ;
1235
+ CELL . get_or_insert :: < Self , _ > ( || format ! ( "[{}]" , <T >:: short_type_path( ) ) )
1236
+ }
1237
+ }
1238
+
1239
+ impl < T : ToOwned > PathOnly for T { }
1240
+
1241
+ impl < T : FromReflect + Clone + TypePath > List for Cow < ' static , [ T ] > {
1242
+ fn get ( & self , index : usize ) -> Option < & dyn Reflect > {
1243
+ self . as_ref ( ) . get ( index) . map ( |x| x as & dyn Reflect )
1244
+ }
1245
+
1246
+ fn get_mut ( & mut self , index : usize ) -> Option < & mut dyn Reflect > {
1247
+ self . to_mut ( ) . get_mut ( index) . map ( |x| x as & mut dyn Reflect )
1248
+ }
1249
+
1250
+ fn len ( & self ) -> usize {
1251
+ self . as_ref ( ) . len ( )
1252
+ }
1253
+
1254
+ fn iter ( & self ) -> crate :: ListIter {
1255
+ crate :: ListIter :: new ( self )
1256
+ }
1257
+
1258
+ fn drain ( self : Box < Self > ) -> Vec < Box < dyn Reflect > > {
1259
+ // into_owned() is not uneccessary here because it avoids cloning whenever you have a Cow::Owned already
1260
+ #[ allow( clippy:: unnecessary_to_owned) ]
1261
+ self . into_owned ( )
1262
+ . into_iter ( )
1263
+ . map ( |value| value. clone_value ( ) )
1264
+ . collect ( )
1265
+ }
1266
+
1267
+ fn insert ( & mut self , index : usize , element : Box < dyn Reflect > ) {
1268
+ let value = element. take :: < T > ( ) . unwrap_or_else ( |value| {
1269
+ T :: from_reflect ( & * value) . unwrap_or_else ( || {
1270
+ panic ! (
1271
+ "Attempted to insert invalid value of type {}." ,
1272
+ value. type_name( )
1273
+ )
1274
+ } )
1275
+ } ) ;
1276
+ self . to_mut ( ) . insert ( index, value) ;
1277
+ }
1278
+
1279
+ fn remove ( & mut self , index : usize ) -> Box < dyn Reflect > {
1280
+ Box :: new ( self . to_mut ( ) . remove ( index) )
1281
+ }
1282
+
1283
+ fn push ( & mut self , value : Box < dyn Reflect > ) {
1284
+ let value = T :: take_from_reflect ( value) . unwrap_or_else ( |value| {
1285
+ panic ! (
1286
+ "Attempted to push invalid value of type {}." ,
1287
+ value. type_name( )
1288
+ )
1289
+ } ) ;
1290
+ self . to_mut ( ) . push ( value) ;
1291
+ }
1292
+
1293
+ fn pop ( & mut self ) -> Option < Box < dyn Reflect > > {
1294
+ self . to_mut ( )
1295
+ . pop ( )
1296
+ . map ( |value| Box :: new ( value) as Box < dyn Reflect > )
1297
+ }
1298
+ }
1299
+
1300
+ impl < T : FromReflect + Clone + TypePath > Reflect for Cow < ' static , [ T ] > {
1301
+ fn type_name ( & self ) -> & str {
1302
+ std:: any:: type_name :: < Self > ( )
1303
+ }
1304
+
1305
+ fn into_any ( self : Box < Self > ) -> Box < dyn Any > {
1306
+ self
1307
+ }
1308
+
1309
+ fn as_any ( & self ) -> & dyn Any {
1310
+ self
1311
+ }
1312
+
1313
+ fn as_any_mut ( & mut self ) -> & mut dyn Any {
1314
+ self
1315
+ }
1316
+
1317
+ fn into_reflect ( self : Box < Self > ) -> Box < dyn Reflect > {
1318
+ self
1319
+ }
1320
+
1321
+ fn as_reflect ( & self ) -> & dyn Reflect {
1322
+ self
1323
+ }
1324
+
1325
+ fn as_reflect_mut ( & mut self ) -> & mut dyn Reflect {
1326
+ self
1327
+ }
1328
+
1329
+ fn apply ( & mut self , value : & dyn Reflect ) {
1330
+ crate :: list_apply ( self , value) ;
1331
+ }
1332
+
1333
+ fn set ( & mut self , value : Box < dyn Reflect > ) -> Result < ( ) , Box < dyn Reflect > > {
1334
+ * self = value. take ( ) ?;
1335
+ Ok ( ( ) )
1336
+ }
1337
+
1338
+ fn reflect_ref ( & self ) -> ReflectRef {
1339
+ ReflectRef :: List ( self )
1340
+ }
1341
+
1342
+ fn reflect_mut ( & mut self ) -> ReflectMut {
1343
+ ReflectMut :: List ( self )
1344
+ }
1345
+
1346
+ fn reflect_owned ( self : Box < Self > ) -> ReflectOwned {
1347
+ ReflectOwned :: List ( self )
1348
+ }
1349
+
1350
+ fn clone_value ( & self ) -> Box < dyn Reflect > {
1351
+ Box :: new ( List :: clone_dynamic ( self ) )
1352
+ }
1353
+
1354
+ fn reflect_hash ( & self ) -> Option < u64 > {
1355
+ crate :: list_hash ( self )
1356
+ }
1357
+
1358
+ fn reflect_partial_eq ( & self , value : & dyn Reflect ) -> Option < bool > {
1359
+ crate :: list_partial_eq ( self , value)
1360
+ }
1361
+
1362
+ fn get_represented_type_info ( & self ) -> Option < & ' static TypeInfo > {
1363
+ Some ( <Self as Typed >:: type_info ( ) )
1364
+ }
1365
+ }
1366
+
1367
+ impl < T : FromReflect + Clone + TypePath > Typed for Cow < ' static , [ T ] > {
1368
+ fn type_info ( ) -> & ' static TypeInfo {
1369
+ static CELL : GenericTypeInfoCell = GenericTypeInfoCell :: new ( ) ;
1370
+ CELL . get_or_insert :: < Self , _ > ( || TypeInfo :: List ( ListInfo :: new :: < Self , T > ( ) ) )
1371
+ }
1372
+ }
1373
+
1374
+ impl < T : FromReflect + Clone + TypePath > GetTypeRegistration for Cow < ' static , [ T ] > {
1375
+ fn get_type_registration ( ) -> TypeRegistration {
1376
+ TypeRegistration :: of :: < Cow < ' static , [ T ] > > ( )
1377
+ }
1378
+ }
1379
+
1380
+ impl < T : FromReflect + Clone + TypePath > FromReflect for Cow < ' static , [ T ] > {
1381
+ fn from_reflect ( reflect : & dyn Reflect ) -> Option < Self > {
1382
+ if let ReflectRef :: List ( ref_list) = reflect. reflect_ref ( ) {
1383
+ let mut temp_vec = Vec :: with_capacity ( ref_list. len ( ) ) ;
1384
+ for field in ref_list. iter ( ) {
1385
+ temp_vec. push ( T :: from_reflect ( field) ?) ;
1386
+ }
1387
+ temp_vec. try_into ( ) . ok ( )
1388
+ } else {
1389
+ None
1390
+ }
1391
+ }
1392
+ }
1393
+
1222
1394
impl Reflect for & ' static Path {
1223
1395
fn type_name ( & self ) -> & str {
1224
1396
std:: any:: type_name :: < Self > ( )
0 commit comments