@@ -58,8 +58,12 @@ impl ExternalPluginStore {
5858 self . registered_plugin_paths . contains ( plugin_path)
5959 }
6060
61+ /// Register plugin.
62+ ///
6163 /// # Panics
62- /// Panics if you use it wrong
64+ /// Panics if:
65+ /// - Plugin at `plugin_path` is already registered.
66+ /// - `offset` does not equal the number of registered rules.
6367 pub fn register_plugin (
6468 & mut self ,
6569 plugin_path : String ,
@@ -68,16 +72,16 @@ impl ExternalPluginStore {
6872 rules : Vec < String > ,
6973 ) {
7074 let newly_inserted = self . registered_plugin_paths . insert ( plugin_path) ;
71- assert ! ( newly_inserted) ;
75+ assert ! ( newly_inserted, "register_plugin: plugin already registered" ) ;
7276
73- let plugin_id: ExternalPluginId = self
77+ let plugin_id = self
7478 . plugins
7579 . push ( ExternalPlugin { name : plugin_name. clone ( ) , rules : FxHashMap :: default ( ) } ) ;
7680 self . plugin_names . insert ( plugin_name, plugin_id) ;
7781
7882 assert ! (
7983 offset == self . rules. len( ) ,
80- "register_plugin: expected offset {}, but rule table is currently {} long" ,
84+ "register_plugin: received offset {}, but rule table is currently {} long" ,
8185 offset,
8286 self . rules. len( )
8387 ) ;
@@ -95,11 +99,11 @@ impl ExternalPluginStore {
9599 plugin_name : & str ,
96100 rule_name : & str ,
97101 ) -> Result < ExternalRuleId , ExternalRuleLookupError > {
98- let plugin_id: & ExternalPluginId = self . plugin_names . get ( plugin_name) . ok_or_else ( || {
102+ let plugin_id = * self . plugin_names . get ( plugin_name) . ok_or_else ( || {
99103 ExternalRuleLookupError :: PluginNotFound { plugin : plugin_name. to_string ( ) }
100104 } ) ?;
101105
102- self . plugins [ * plugin_id] . rules . get ( rule_name) . copied ( ) . ok_or_else ( || {
106+ self . plugins [ plugin_id] . rules . get ( rule_name) . copied ( ) . ok_or_else ( || {
103107 ExternalRuleLookupError :: RuleNotFound {
104108 plugin : plugin_name. to_string ( ) ,
105109 rule : rule_name. to_string ( ) ,
@@ -137,13 +141,13 @@ impl fmt::Display for ExternalRuleLookupError {
137141
138142impl std:: error:: Error for ExternalRuleLookupError { }
139143
140- #[ derive( Debug , Default ) ]
144+ #[ derive( Debug ) ]
141145struct ExternalPlugin {
142146 name : String ,
143147 rules : FxHashMap < String , ExternalRuleId > ,
144148}
145149
146- #[ derive( Debug , Default , PartialEq , Eq ) ]
150+ #[ derive( Debug ) ]
147151struct ExternalRule {
148152 name : String ,
149153 plugin_id : ExternalPluginId ,
0 commit comments