conformal_component::parameters

Function override_defaults

Source
pub fn override_defaults<'a, S: AsRef<str> + 'a, H: BuildHasher>(
    infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a,
    overrides: &HashMap<&str, InternalValue, H>,
) -> HashMap<String, InternalValue>
Expand description

Helper function to get a map of param values based on the default values from a list of Infos.

Note that if you are passing these parameters to a synth, likely you want to use override_synth_defaults instead.

ยงExamples

let infos = vec![
   StaticInfoRef {
     title: "Numeric",
     short_title: "Numeric",
     unique_id: "numeric",
     flags: Default::default(),
     type_specific: TypeSpecificInfoRef::Numeric {
       default: 0.0,
       valid_range: 0.0..=1.0,
       units: None,
     },
   },
];

// Without overriding, we'll just get a map containing
// the default values.
assert_eq!(
  override_defaults(infos.iter().cloned(), &HashMap::new()).get("numeric"),
  Some(&InternalValue::Numeric(0.0))
);

// If we override the default value, we'll get that instead.
assert_eq!(
  override_defaults(
    infos.iter().cloned(),
    &vec![("numeric", InternalValue::Numeric(0.5))].into_iter().collect::<HashMap<_, _>>()
  ).get("numeric"),
  Some(&InternalValue::Numeric(0.5))
 );