#[non_exhaustive]pub struct Config {
pub file_path: Option<String>,
pub listener: Option<ListenerConfig>,
pub log: Option<LogConfig>,
pub service: ServiceConfig,
pub file_tree_view: Option<FileTreeViewConfig>,
}Expand description
Top-level application configuration, corresponding one-to-one with
apimock.toml.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.file_path: Option<String>Where this config was loaded from. Kept so we can resolve relative paths (rule sets, middlewares, respond dirs) against the config file’s parent directory — not the process’s working directory.
listener: Option<ListenerConfig>§log: Option<LogConfig>§service: ServiceConfig§file_tree_view: Option<FileTreeViewConfig>Optional filter configuration for FileTreeView. When absent,
FileTreeViewConfig::default()
applies (dotfiles hidden, built-in excludes on).
Implementations§
Source§impl Config
impl Config
Sourcepub fn new(
config_file_path: Option<&String>,
fallback_respond_dir_path: Option<&String>,
) -> ConfigResult<Self>
pub fn new( config_file_path: Option<&String>, fallback_respond_dir_path: Option<&String>, ) -> ConfigResult<Self>
Build a Config by reading the TOML file, resolving rule-set
paths, and validating the result.
Middleware paths are recorded on the returned Config but not compiled here — the server crate performs compilation. See the module docstring for why.
Sourcepub fn compute_fallback_respond_dir(
&mut self,
fallback_respond_dir_path: Option<&String>,
) -> ConfigResult<()>
pub fn compute_fallback_respond_dir( &mut self, fallback_respond_dir_path: Option<&String>, ) -> ConfigResult<()>
Resolve the fallback respond dir against the config file’s parent directory. See the module doc for why we don’t resolve against CWD.
Sourcepub fn listener_http_addr(&self) -> Option<String>
pub fn listener_http_addr(&self) -> Option<String>
HTTP listener address, if HTTP is enabled.
Sourcepub fn listener_https_addr(&self) -> Option<String>
pub fn listener_https_addr(&self) -> Option<String>
HTTPS listener address, if TLS is configured.
Sourcepub fn current_dir_to_parent_dir_relative_path(&self) -> ConfigResult<String>
pub fn current_dir_to_parent_dir_relative_path(&self) -> ConfigResult<String>
Relative path from CWD to the parent dir of the config file.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Config
impl Display for Config
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
RFC 079 M-03a: every let _ = write!(f, ...) / writeln! in a
Display impl across this workspace discards a fmt::Result on
purpose, not by oversight — written once here rather than at
each of the ~30 other sites, per the RFC’s own “do the minimum”
instruction (30-odd near-identical edits would be churn, not
clarity).
write!/writeln! against f: &mut Formatter can only fail if
the sink Formatter wraps fails, and every caller of a
Display impl in this project reaches one through format!,
.to_string(), or println! — all backed by a String (or, for
println!, stdout, which this project never checks either, and
for the same reason: a broken stdout pipe is not a case any of
these callers recover from or report on). std::fmt::Write for String cannot return Err — the only way writing to a String
fails is running out of memory, which aborts the process rather
than returning a recoverable error. So fmt::Error is
unreachable in practice at every one of these call sites, and an
if let Err(e) = write!(...) handler at each would be a dead
branch dressed up as error handling, not real robustness.