component_model 0.22.1

Revolutionary type-safe component assignment for Rust. Build complex objects with zero boilerplate using derive macros and type-driven field setting. Perfect for configuration builders, fluent APIs, and object composition patterns.
Documentation
// Shared fixture included by composite_manual.rs and components_assign_manual.rs via include!().
// Extracted to eliminate ~160 lines of near-identical Options1/Options2 struct definitions,
// From impls, Assign impls, and ComponentsAssign trait+blanket-impl blocks that previously
// appeared verbatim in both files. composite_manual.rs adds its unique impl<T> From<T> for
// Options2 after including this file; components_assign_manual.rs uses just this fixture.

///
/// Options1
///
#[ derive( Debug, Default, PartialEq ) ]
pub struct Options1
{
  field1: i32,
  field2: String,
  field3: f32,
}

impl From< &Options1 > for i32
{
  #[ inline( always ) ]
  fn from( src: &Options1 ) -> Self
  {
  src.field1
 }
}

impl From< &Options1 > for String
{
  #[ inline( always ) ]
  fn from( src: &Options1 ) -> Self
  {
  src.field2.clone()
 }
}

impl From< &Options1 > for f32
{
  #[ inline( always ) ]
  fn from( src: &Options1 ) -> Self
  {
  src.field3
 }
}

impl< IntoT > the_module ::Assign< i32, IntoT > for Options1
where
  IntoT: Into< i32 >,
{
  #[ inline( always ) ]
  fn assign( &mut self, component: IntoT )
  {
  self.field1 = component.into();
 }
}

impl< IntoT > the_module ::Assign< String, IntoT > for Options1
where
  IntoT: Into< String >,
{
  #[ inline( always ) ]
  fn assign( &mut self, component: IntoT )
  {
  self.field2.clone_from( &component.into() );
 }
}

impl< IntoT > the_module ::Assign< f32, IntoT > for Options1
where
  IntoT: Into< f32 >,
{
  #[ inline( always ) ]
  fn assign( &mut self, component: IntoT )
  {
  self.field3 = component.into();
 }
}

///
/// `Options1ComponentsAssign`.
///
pub trait Options1ComponentsAssign< IntoT >
where
  IntoT: Into< i32 >,
  IntoT: Into< String >,
  IntoT: Into< f32 >,
  IntoT: Clone,
{
  fn options_1_assign( &mut self, component: IntoT );
}

impl< T, IntoT > Options1ComponentsAssign< IntoT > for T
where
  T: the_module ::Assign< i32, IntoT >,
  T: the_module ::Assign< String, IntoT >,
  T: the_module ::Assign< f32, IntoT >,
  IntoT: Into< i32 >,
  IntoT: Into< String >,
  IntoT: Into< f32 >,
  IntoT: Clone,
{
  #[ inline( always ) ]
  fn options_1_assign( &mut self, component: IntoT )
  {
  the_module ::Assign :: < i32, _ > ::assign( self, component.clone() );
  the_module ::Assign :: < String, _ > ::assign( self, component.clone() );
  the_module ::Assign :: < f32, _ > ::assign( self, component.clone() );
 }
}

///
/// Options2
///
#[ derive( Debug, Default, PartialEq ) ]
pub struct Options2
{
  field1: i32,
  field2: String,
}

impl From< &Options2 > for i32
{
  #[ inline( always ) ]
  fn from( src: &Options2 ) -> Self
  {
  src.field1
 }
}

impl From< &Options2 > for String
{
  #[ inline( always ) ]
  fn from( src: &Options2 ) -> Self
  {
  src.field2.clone()
 }
}

impl< IntoT > the_module ::Assign< i32, IntoT > for Options2
where
  IntoT: Into< i32 >,
{
  #[ inline( always ) ]
  fn assign( &mut self, component: IntoT )
  {
  self.field1 = component.into();
 }
}

impl< IntoT > the_module ::Assign< String, IntoT > for Options2
where
  IntoT: Into< String >,
{
  #[ inline( always ) ]
  fn assign( &mut self, component: IntoT )
  {
  self.field2.clone_from( &component.into() );
 }
}

///
/// `Options2ComponentsAssign`.
///
pub trait Options2ComponentsAssign< IntoT >
where
  IntoT: Into< i32 >,
  IntoT: Into< String >,
  IntoT: Clone,
{
  fn options_2_assign( &mut self, component: IntoT );
}

impl< T, IntoT > Options2ComponentsAssign< IntoT > for T
where
  T: the_module ::Assign< i32, IntoT >,
  T: the_module ::Assign< String, IntoT >,
  IntoT: Into< i32 >,
  IntoT: Into< String >,
  IntoT: Clone,
{
  #[ inline( always ) ]
  fn options_2_assign( &mut self, component: IntoT )
  {
  the_module ::Assign :: < i32, _ > ::assign( self, component.clone() );
  the_module ::Assign :: < String, _ > ::assign( self, component.clone() );
 }
}