Trait Assign

Source
pub trait Assign<T, IntoT>
where IntoT: Into<T>,
{ // Required method fn assign(&mut self, component: IntoT); // Provided method fn impute(self, component: IntoT) -> Self where Self: Sized { ... } }
Expand description

Provides a generic interface for setting a component of a certain type on an object.

This trait abstracts the action of setting or replacing a component, where a component can be any part or attribute of an object, such as a field value. It is designed to be generic over the type of the component being set (T) and the type that can be converted into the component (IntoT). This design allows for flexible implementations that can accept various types that can then be converted into the required component type.

§Type Parameters

  • T: The type of the component to be set on the implementing object. This type represents the final form of the component as it should be stored or represented in the object.
  • IntoT: The type that can be converted into T. This allows the assign method to accept different types that are capable of being transformed into the required component type T, providing greater flexibility in setting the component.

§Examples

Implementing Assign to set a name string on a struct:

use component_model_types::Assign; // use crate `component_model` instead of crate `component_model_types` unless you need to use crate `component_model_types` directly

struct MyStruct {
  name: String,
}

impl< IntoT : Into< String > > Assign< String, IntoT > for MyStruct
{
  fn assign( &mut self, component : IntoT )
  {
    self.name = component.into();
  }
}

let mut obj = MyStruct { name : String::new() };
obj.assign( "New Name" );
assert_eq!( obj.name, "New Name" );

Required Methods§

Source

fn assign(&mut self, component: IntoT)

Sets or replaces the component on the object with the given value.

This method takes ownership of the given value (component), which is of type IntoT. component is then converted into type T and set as the component of the object.

Provided Methods§

Source

fn impute(self, component: IntoT) -> Self
where Self: Sized,

Sets or replaces the component on the object with the given value. Unlike function (assing) function (impute) also consumes self and return it what is useful for builder pattern.

Implementors§

Source§

impl<Marker, IntoT> Assign<AttributePropertyBoolean<Marker>, IntoT> for AttributePropertyBoolean<Marker>
where IntoT: Into<AttributePropertyBoolean<Marker>>,

Source§

impl<Marker, IntoT> Assign<AttributePropertyOptionalBoolean<Marker>, IntoT> for AttributePropertyOptionalBoolean<Marker>
where IntoT: Into<AttributePropertyOptionalBoolean<Marker>>,

Source§

impl<Marker, IntoT> Assign<AttributePropertyOptionalSingletone<Marker>, IntoT> for AttributePropertyOptionalSingletone<Marker>

Source§

impl<Marker, IntoT> Assign<AttributePropertySingletone<Marker>, IntoT> for AttributePropertySingletone<Marker>
where IntoT: Into<AttributePropertySingletone<Marker>>,

Source§

impl<T, Marker, IntoT> Assign<AttributePropertyOptionalSyn<T, Marker>, IntoT> for AttributePropertyOptionalSyn<T, Marker>
where T: Parse + ToTokens, IntoT: Into<AttributePropertyOptionalSyn<T, Marker>>,

Source§

impl<T, Marker, IntoT> Assign<AttributePropertySyn<T, Marker>, IntoT> for AttributePropertySyn<T, Marker>
where T: Parse + ToTokens, IntoT: Into<AttributePropertySyn<T, Marker>>,