File tree Expand file tree Collapse file tree 1 file changed +8
-16
lines changed Expand file tree Collapse file tree 1 file changed +8
-16
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ use core::any::Any;
44use core:: clone:: Clone ;
55use core:: convert:: TryInto ;
66use core:: ops:: Deref ;
7- use core:: result:: Result :: { Err , Ok } ;
87
98use std:: boxed:: Box ;
109
@@ -15,32 +14,25 @@ fn test_owned_clone() {
1514 assert ! ( a == b) ;
1615}
1716
18- #[ derive( PartialEq , Eq ) ]
17+ #[ derive( Debug , PartialEq , Eq ) ]
1918struct Test ;
2019
2120#[ test]
2221fn any_move ( ) {
2322 let a = Box :: new ( 8 ) as Box < dyn Any > ;
2423 let b = Box :: new ( Test ) as Box < dyn Any > ;
2524
26- match a. downcast :: < i32 > ( ) {
27- Ok ( a) => {
28- assert ! ( a == Box :: new( 8 ) ) ;
29- }
30- Err ( ..) => panic ! ( ) ,
31- }
32- match b. downcast :: < Test > ( ) {
33- Ok ( a) => {
34- assert ! ( a == Box :: new( Test ) ) ;
35- }
36- Err ( ..) => panic ! ( ) ,
37- }
25+ let a: Box < i32 > = a. downcast :: < i32 > ( ) . unwrap ( ) ;
26+ assert_eq ! ( * a, 8 ) ;
27+
28+ let b: Box < Test > = b. downcast :: < Test > ( ) . unwrap ( ) ;
29+ assert_eq ! ( * b, Test ) ;
3830
3931 let a = Box :: new ( 8 ) as Box < dyn Any > ;
4032 let b = Box :: new ( Test ) as Box < dyn Any > ;
4133
42- assert ! ( a. downcast:: <Box <Test >>( ) . is_err( ) ) ;
43- assert ! ( b. downcast:: <Box <i32 >>( ) . is_err( ) ) ;
34+ assert ! ( a. downcast:: <Box <i32 >>( ) . is_err( ) ) ;
35+ assert ! ( b. downcast:: <Box <Test >>( ) . is_err( ) ) ;
4436}
4537
4638#[ test]
You can’t perform that action at this time.
0 commit comments