pub struct SourcedConfig<State = ConfigLoaded> {
pub global: SourcedGlobalConfig,
pub per_file_ignores: SourcedValue<HashMap<String, Vec<String>>>,
pub per_file_flavor: SourcedValue<IndexMap<String, MarkdownFlavor>>,
pub rules: BTreeMap<String, SourcedRuleConfig>,
pub loaded_files: Vec<String>,
pub unknown_keys: Vec<(String, String, Option<String>)>,
pub project_root: Option<PathBuf>,
pub validation_warnings: Vec<ConfigValidationWarning>,
/* private fields */
}Expand description
Configuration with provenance tracking for values.
The State type parameter encodes the validation state:
ConfigLoaded: Config has been loaded but not validatedConfigValidated: Config has been validated and can be converted toConfig
§Typestate Pattern
This uses the typestate pattern to ensure validation happens before conversion:
let loaded: SourcedConfig<ConfigLoaded> = SourcedConfig::load_with_discovery(...)?;
let validated: SourcedConfig<ConfigValidated> = loaded.validate(®istry)?;
let config: Config = validated.into(); // Only works on ConfigValidated!Attempting to convert a ConfigLoaded config directly to Config is a compile error.
Fields§
§global: SourcedGlobalConfig§per_file_ignores: SourcedValue<HashMap<String, Vec<String>>>§per_file_flavor: SourcedValue<IndexMap<String, MarkdownFlavor>>§rules: BTreeMap<String, SourcedRuleConfig>§loaded_files: Vec<String>§unknown_keys: Vec<(String, String, Option<String>)>§project_root: Option<PathBuf>Project root directory (parent of config file), used for resolving relative paths
validation_warnings: Vec<ConfigValidationWarning>Validation warnings (populated after validate() is called)
Implementations§
Source§impl SourcedConfig<ConfigLoaded>
impl SourcedConfig<ConfigLoaded>
Sourcepub fn load(
config_path: Option<&str>,
cli_overrides: Option<&SourcedGlobalConfig>,
) -> Result<Self, ConfigError>
pub fn load( config_path: Option<&str>, cli_overrides: Option<&SourcedGlobalConfig>, ) -> Result<Self, ConfigError>
Load and merge configurations from files and CLI overrides.
Sourcepub fn load_with_discovery(
config_path: Option<&str>,
cli_overrides: Option<&SourcedGlobalConfig>,
skip_auto_discovery: bool,
) -> Result<Self, ConfigError>
pub fn load_with_discovery( config_path: Option<&str>, cli_overrides: Option<&SourcedGlobalConfig>, skip_auto_discovery: bool, ) -> Result<Self, ConfigError>
Load and merge configurations from files and CLI overrides. If skip_auto_discovery is true, only explicit config paths are loaded.
Sourcepub fn validate(
self,
registry: &RuleRegistry,
) -> Result<SourcedConfig<ConfigValidated>, ConfigError>
pub fn validate( self, registry: &RuleRegistry, ) -> Result<SourcedConfig<ConfigValidated>, ConfigError>
Validate the configuration against a rule registry.
This method transitions the config from ConfigLoaded to ConfigValidated state,
enabling conversion to Config. Validation warnings are stored in the config
and can be displayed to the user.
§Example
let loaded = SourcedConfig::load_with_discovery(path, None, false)?;
let validated = loaded.validate(®istry)?;
let config: Config = validated.into();Sourcepub fn validate_into(
self,
registry: &RuleRegistry,
) -> Result<(Config, Vec<ConfigValidationWarning>), ConfigError>
pub fn validate_into( self, registry: &RuleRegistry, ) -> Result<(Config, Vec<ConfigValidationWarning>), ConfigError>
Validate and convert to Config in one step (convenience method).
This combines validate() and into() for callers who want the
validation warnings separately.
Sourcepub fn into_validated_unchecked(self) -> SourcedConfig<ConfigValidated>
pub fn into_validated_unchecked(self) -> SourcedConfig<ConfigValidated>
Skip validation and convert directly to ConfigValidated state.
§Safety
This method bypasses validation. Use only when:
- You’ve already validated via
validate_config_sourced() - You’re in test code that doesn’t need validation
- You’re migrating legacy code and will add proper validation later
Prefer validate() for new code.
Trait Implementations§
Source§impl<State: Clone> Clone for SourcedConfig<State>
impl<State: Clone> Clone for SourcedConfig<State>
Source§fn clone(&self) -> SourcedConfig<State>
fn clone(&self) -> SourcedConfig<State>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<State: Debug> Debug for SourcedConfig<State>
impl<State: Debug> Debug for SourcedConfig<State>
Source§impl Default for SourcedConfig<ConfigLoaded>
impl Default for SourcedConfig<ConfigLoaded>
Source§impl From<SourcedConfig<ConfigValidated>> for Config
Convert a validated configuration to the final Config type.
impl From<SourcedConfig<ConfigValidated>> for Config
Convert a validated configuration to the final Config type.
This implementation only exists for SourcedConfig<ConfigValidated>,
ensuring that validation must occur before conversion.
Source§fn from(sourced: SourcedConfig<ConfigValidated>) -> Self
fn from(sourced: SourcedConfig<ConfigValidated>) -> Self
Auto Trait Implementations§
impl<State> Freeze for SourcedConfig<State>
impl<State> RefUnwindSafe for SourcedConfig<State>where
State: RefUnwindSafe,
impl<State> Send for SourcedConfig<State>where
State: Send,
impl<State> Sync for SourcedConfig<State>where
State: Sync,
impl<State> Unpin for SourcedConfig<State>where
State: Unpin,
impl<State> UnwindSafe for SourcedConfig<State>where
State: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more