pub struct RuleSet {
pub prefix: Option<Prefix>,
pub default: Option<DefaultRespond>,
pub guard: Option<Guard>,
pub rules: Vec<Rule>,
pub file_path: String,
}Expand description
A named collection of routing rules, loaded from one TOML file.
§Why rule sets, not a single flat rule list
Large mock APIs tend to group related endpoints (e.g. all of /api/v1
under one auth scheme). A rule set lets operators share a URL prefix
and a respond-dir prefix across many rules, and to split their config
across multiple files that can be enabled/disabled independently.
Match order across sets is determined by the order in
service.rule_sets, so the most specific set can be listed first.
Fields§
§prefix: Option<Prefix>§default: Option<DefaultRespond>§guard: Option<Guard>§rules: Vec<Rule>§file_path: StringImplementations§
Source§impl RuleSet
impl RuleSet
Sourcepub fn new(
rule_set_file_path: &str,
current_dir_to_config_dir_relative_path: &str,
rule_set_idx: usize,
) -> RoutingResult<Self>
pub fn new( rule_set_file_path: &str, current_dir_to_config_dir_relative_path: &str, rule_set_idx: usize, ) -> RoutingResult<Self>
Load a rule set from a TOML file on disk.
§Why errors are typed and not panics
In 4.6.x this used expect + panic!, so a missing or malformed
rule set aborted the process. Because rule sets are edited
frequently during development, those panics were a common papercut.
Now any failure becomes an RoutingError::RuleSetRead / ::RuleSetParse
that the caller can surface cleanly.
Sourcepub fn find_matched(
&self,
parsed_request: &ParsedRequest,
strategy: Option<&Strategy>,
rule_set_idx: usize,
) -> Option<Respond>
pub fn find_matched( &self, parsed_request: &ParsedRequest, strategy: Option<&Strategy>, rule_set_idx: usize, ) -> Option<Respond>
find rule matching request and return its respond content
Sourcepub fn dir_prefix(&self) -> String
pub fn dir_prefix(&self) -> String
dir_prefix as string possibly as empty