3
3
*
4
4
* This Source Code Form is subject to the terms of the Mozilla Public
5
5
* License, v. 2.0. If a copy of the MPL was not distributed with this
6
- * file, you can obtain one at http ://mozilla.org/MPL/2.0/.
6
+ * file, you can obtain one at https ://mozilla.org/MPL/2.0/.
7
7
*/
8
8
9
9
use std:: f64:: consts:: PI ;
@@ -42,7 +42,13 @@ macro_rules! body {
42
42
}
43
43
44
44
fn name( & self ) -> & ' static str {
45
- stringify!( $ident)
45
+ stringify!( $i)
46
+ }
47
+ }
48
+
49
+ impl Display for $i {
50
+ fn fmt( & self , f: & mut Formatter <' _>) -> std:: fmt:: Result {
51
+ write!( f, "{}" , self . name( ) )
46
52
}
47
53
}
48
54
} ;
@@ -59,6 +65,12 @@ macro_rules! body {
59
65
$name
60
66
}
61
67
}
68
+
69
+ impl Display for $i {
70
+ fn fmt( & self , f: & mut Formatter <' _>) -> std:: fmt:: Result {
71
+ write!( f, "{}" , self . name( ) )
72
+ }
73
+ }
62
74
} ;
63
75
}
64
76
@@ -659,18 +671,7 @@ mod tests {
659
671
// Jupiter is manually redefined here using known data. This avoids a dependency on the
660
672
// correctness of the PCK parser to test RotationalElements, and prevents compiler errors
661
673
// when generated files are malformed or deleted in preparation for regeneration.
662
- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
663
- struct Jupiter ;
664
-
665
- impl Body for Jupiter {
666
- fn id ( & self ) -> NaifId {
667
- NaifId ( 599 )
668
- }
669
-
670
- fn name ( & self ) -> & ' static str {
671
- "Jupiter"
672
- }
673
- }
674
+ body ! { Jupiter , 599 }
674
675
675
676
impl PointMass for Jupiter {
676
677
fn gravitational_parameter ( ) -> f64 {
@@ -788,6 +789,23 @@ mod tests {
788
789
) ;
789
790
}
790
791
792
+ body ! { Rupert , "Persephone/Rupert" , 1099 }
793
+
794
+ #[ test]
795
+ fn test_body ( ) {
796
+ let body = Jupiter ;
797
+ let id = body. id ( ) . 0 ;
798
+ let name = body. name ( ) ;
799
+ assert_eq ! ( id, 599 ) ;
800
+ assert_eq ! ( name, "Jupiter" ) ;
801
+
802
+ let body = Rupert ;
803
+ let id = body. id ( ) . 0 ;
804
+ let name = body. name ( ) ;
805
+ assert_eq ! ( id, 1099 ) ;
806
+ assert_eq ! ( name, "Persephone/Rupert" ) ;
807
+ }
808
+
791
809
#[ test]
792
810
fn test_naif_id ( ) {
793
811
let id = NaifId ( 0 ) ;
0 commit comments