former 2.43.0

A flexible implementation of the Builder pattern supporting nested builders and collection-specific subformers. Simplify the construction of complex objects.
Documentation

//! Example demonstrating how to configure a `HashMap` using collection setters with Former.

#![allow(missing_docs)]

//
// This example demonstrates how to effectively employ the `Former` to configure a `HashMap` using a collection setter.
//

#[cfg(not(all(
  feature = "enabled",
  feature = "derive_former",
  any(feature = "use_alloc", not(feature = "no_std"))
)))]
fn main() {}
#[cfg(all(
  feature = "enabled",
  feature = "derive_former",
  any(feature = "use_alloc", not(feature = "no_std"))
))]
fn main() {
  use collection_tools::{HashMap, hmap};

  #[ derive( Debug, PartialEq, former::Former ) ]
  pub struct StructWithMap {
    map: HashMap<&'static str, &'static str>,
  }

  let instance = StructWithMap::former().map(hmap! { "a" => "b", "c" => "d" }).form();
  assert_eq!(
    instance,
    StructWithMap {
      map: hmap! { "a" => "b", "c" => "d" }
    }
  );
  dbg!(instance);
}