@@ -6,92 +6,102 @@ use crate::names::traits::SingleNameTrait;
66
77/// Stores information about a constant or variable name.
88/// The name itself isn't stored here.
9- pub struct NameInfo ( NameInfoInner ) ;
9+ pub struct NameInfo {
10+ inner : NameInfoInner ,
11+ }
1012
1113impl NameInfo {
1214 pub fn constant ( v : Variant ) -> Self {
13- Self ( NameInfoInner :: Constant ( v) )
15+ Self {
16+ inner : NameInfoInner :: Constant { value : v } ,
17+ }
1418 }
1519
1620 pub fn compacts ( ) -> Self {
17- Self ( NameInfoInner :: Compacts ( Compacts :: default ( ) ) )
21+ Self {
22+ inner : NameInfoInner :: Compacts {
23+ compacts : Compacts :: default ( ) ,
24+ } ,
25+ }
1826 }
1927
2028 pub fn extended ( variable_info : VariableInfo ) -> Self {
21- Self ( NameInfoInner :: Extended ( variable_info) )
29+ Self {
30+ inner : NameInfoInner :: Extended { variable_info } ,
31+ }
2232 }
2333}
2434
2535impl SingleNameTrait for NameInfo {
2636 fn get_compact ( & self , qualifier : TypeQualifier ) -> Option < & VariableInfo > {
27- self . 0 . get_compact ( qualifier)
37+ self . inner . get_compact ( qualifier)
2838 }
2939
3040 fn get_extended ( & self ) -> Option < & VariableInfo > {
31- self . 0 . get_extended ( )
41+ self . inner . get_extended ( )
3242 }
3343
3444 fn get_const_value ( & self ) -> Option < & Variant > {
35- self . 0 . get_const_value ( )
45+ self . inner . get_const_value ( )
3646 }
3747
3848 fn collect_var_info ( & self , only_shared : bool ) -> Vec < ( BuiltInStyle , & VariableInfo ) > {
39- self . 0 . collect_var_info ( only_shared)
49+ self . inner . collect_var_info ( only_shared)
4050 }
4151
4252 fn insert_compact ( & mut self , variable_info : VariableInfo ) {
43- self . 0 . insert_compact ( variable_info) ;
53+ self . inner . insert_compact ( variable_info) ;
4454 }
4555}
4656
4757/// Nested enum for [NameInfo].
4858/// The external struct is preventing direct access to the enum members
4959/// outside of the module.
5060enum NameInfoInner {
51- Constant ( Variant ) ,
52- Compacts ( Compacts ) ,
53- Extended ( VariableInfo ) ,
61+ Constant { value : Variant } ,
62+ Compacts { compacts : Compacts } ,
63+ Extended { variable_info : VariableInfo } ,
5464}
5565
5666impl SingleNameTrait for NameInfoInner {
5767 fn get_compact ( & self , qualifier : TypeQualifier ) -> Option < & VariableInfo > {
5868 match self {
59- Self :: Compacts ( compacts) => compacts. get_compact ( qualifier) ,
69+ Self :: Compacts { compacts } => compacts. get_compact ( qualifier) ,
6070 _ => None ,
6171 }
6272 }
6373
6474 fn get_extended ( & self ) -> Option < & VariableInfo > {
6575 match self {
66- Self :: Extended ( v ) => Some ( v ) ,
76+ Self :: Extended { variable_info } => Some ( variable_info ) ,
6777 _ => None ,
6878 }
6979 }
7080
7181 fn get_const_value ( & self ) -> Option < & Variant > {
7282 match self {
73- Self :: Constant ( v ) => Some ( v ) ,
83+ Self :: Constant { value } => Some ( value ) ,
7484 _ => None ,
7585 }
7686 }
7787
7888 fn collect_var_info ( & self , only_shared : bool ) -> Vec < ( BuiltInStyle , & VariableInfo ) > {
7989 match self {
80- Self :: Compacts ( compacts) => compacts. collect_var_info ( only_shared) ,
81- Self :: Extended ( v ) => {
82- if v . shared || !only_shared {
83- vec ! [ ( BuiltInStyle :: Extended , v ) ]
90+ Self :: Compacts { compacts } => compacts. collect_var_info ( only_shared) ,
91+ Self :: Extended { variable_info } => {
92+ if variable_info . shared || !only_shared {
93+ vec ! [ ( BuiltInStyle :: Extended , variable_info ) ]
8494 } else {
8595 vec ! [ ]
8696 }
8797 }
88- Self :: Constant ( _ ) => vec ! [ ] ,
98+ Self :: Constant { .. } => vec ! [ ] ,
8999 }
90100 }
91101
92102 fn insert_compact ( & mut self , variable_info : VariableInfo ) {
93103 match self {
94- Self :: Compacts ( compacts) => compacts. insert_compact ( variable_info) ,
104+ Self :: Compacts { compacts } => compacts. insert_compact ( variable_info) ,
95105 _ => panic ! ( "Cannot insert compact because it already exists as CONST or extended" ) ,
96106 }
97107 }
0 commit comments