MCPcopy Index your code
hub / github.com/encounter/objdiff / apply_project_options

Function apply_project_options

objdiff-core/src/config/mod.rs:331–372  ·  view source on GitHub ↗
(
    diff_config: &mut crate::diff::DiffObjConfig,
    options: &ProjectOptions,
)

Source from the content-addressed store, hash-verified

329
330#[cfg(feature = "any-arch")]
331pub fn apply_project_options(
332 diff_config: &mut crate::diff::DiffObjConfig,
333 options: &ProjectOptions,
334) -> Result<()> {
335 use core::str::FromStr;
336
337 use crate::diff::{ConfigEnum, ConfigPropertyId, ConfigPropertyKind};
338
339 let mut result = Ok(());
340 for (key, value) in options.iter() {
341 let property_id = ConfigPropertyId::from_str(key)
342 .map_err(|()| anyhow!("Invalid configuration property: {key}"))?;
343 let value = match value {
344 ProjectOptionValue::Bool(value) => Cow::Borrowed(if *value { "true" } else { "false" }),
345 ProjectOptionValue::String(value) => Cow::Borrowed(value.as_str()),
346 };
347 if diff_config.set_property_value_str(property_id, &value).is_err() {
348 if result.is_err() {
349 // Already returning an error, skip further errors
350 continue;
351 }
352 let mut expected = String::new();
353 match property_id.kind() {
354 ConfigPropertyKind::Boolean => expected.push_str("true, false"),
355 ConfigPropertyKind::Choice(variants) => {
356 for (idx, variant) in variants.iter().enumerate() {
357 if idx > 0 {
358 expected.push_str(", ");
359 }
360 expected.push_str(variant.value);
361 }
362 }
363 }
364 result = Err(anyhow!(
365 "Invalid value for {}. Expected one of: {}",
366 property_id.name(),
367 expected
368 ));
369 }
370 }
371 result
372}

Callers 4

load_project_configFunction · 0.85
effective_diff_configMethod · 0.85
build_unit_diff_configFunction · 0.85
build_config_from_argsFunction · 0.85

Calls 1

from_strFunction · 0.85

Tested by

no test coverage detected