pub struct HashMapSubformer<K, E, Formed, Context, End>
where K: Eq + Hash, Formed: HashMapLike<K, E> + Default, End: FormingEnd<Formed, Context>,
{ /* private fields */ }
Expand description

A builder for constructing hash map-like structures with a fluent interface.

HashMapSubformer leverages the HashMapLike trait to enable a flexible and customizable way to build hash map-like structures. It supports the chaining of insert operations and allows for the definition of custom end actions to finalize the building process.

§Type Parameters

  • K: Key type, must implement Eq and Hash.
  • E: Element (value) type.
  • Formed: The hash map-like formed being built.
  • Context: Type of the optional context used during the building process.
  • End: End-of-forming action to be executed upon completion.

§Examples


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

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

Implementations§

source§

impl<K, E, Formed, Context, End> HashMapSubformer<K, E, Formed, Context, End>
where K: Eq + Hash, Formed: HashMapLike<K, E> + Default, End: FormingEnd<Formed, Context>,

source

pub fn form(self) -> Formed

Form current former into target structure.

source

pub fn begin( formed: Option<Formed>, context: Option<Context>, on_end: End ) -> Self

Make a new HashMapSubformer. It should be called by a context generated for your structure. The context is returned after completion of forming by function `on_end``.

source

pub fn end(self) -> Context

Return context of your struct moving formed there. Should be called after configuring the formed.

source

pub fn replace(self, formed: Formed) -> Self

Set the whole formed instead of setting each element individually.

source§

impl<K, E, Formed> HashMapSubformer<K, E, Formed, Formed, ReturnFormed>
where K: Eq + Hash, Formed: HashMapLike<K, E> + Default,

source

pub fn new() -> Self

Create a new instance without context or on end processing. It just returns continaer on end of forming.

source§

impl<K, E, Formed, Context, End> HashMapSubformer<K, E, Formed, Context, End>
where K: Eq + Hash, Formed: HashMapLike<K, E> + Default, End: FormingEnd<Formed, Context>,

source

pub fn insert<K2, E2>(self, k: K2, e: E2) -> Self
where K2: Into<K>, E2: Into<E>,

Inserts a key-value pair into the formed. If the formed doesn’t exist, it is created.

§Parameters
  • k: The key for the value to be inserted. Will be converted into the formed’s key type.
  • e: The value to be inserted. Will be converted into the formed’s value type.
§Returns

Returns self for chaining further insertions or operations.

source

pub fn push<K2, E2>(self, k: K2, e: E2) -> Self
where K2: Into<K>, E2: Into<E>,

Alias for insert.

§Parameters
  • k: The key for the value to be inserted. Will be converted into the formed’s key type.
  • e: The value to be inserted. Will be converted into the formed’s value type.
§Returns

Returns self for chaining further insertions or operations.

Trait Implementations§

source§

impl<K, E: Debug, Formed, Context: Debug, End> Debug for HashMapSubformer<K, E, Formed, Context, End>
where K: Eq + Hash + Debug, Formed: HashMapLike<K, E> + Default + Debug, End: FormingEnd<Formed, Context> + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K, E: Default, Formed, Context: Default, End> Default for HashMapSubformer<K, E, Formed, Context, End>
where K: Eq + Hash + Default, Formed: HashMapLike<K, E> + Default + Default, End: FormingEnd<Formed, Context> + Default,

source§

fn default() -> HashMapSubformer<K, E, Formed, Context, End>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, E, Formed, Context, End> Freeze for HashMapSubformer<K, E, Formed, Context, End>
where Context: Freeze, End: Freeze, Formed: Freeze,

§

impl<K, E, Formed, Context, End> RefUnwindSafe for HashMapSubformer<K, E, Formed, Context, End>

§

impl<K, E, Formed, Context, End> Send for HashMapSubformer<K, E, Formed, Context, End>
where Context: Send, E: Send, End: Send, Formed: Send, K: Send,

§

impl<K, E, Formed, Context, End> Sync for HashMapSubformer<K, E, Formed, Context, End>
where Context: Sync, E: Sync, End: Sync, Formed: Sync, K: Sync,

§

impl<K, E, Formed, Context, End> Unpin for HashMapSubformer<K, E, Formed, Context, End>
where Context: Unpin, E: Unpin, End: Unpin, Formed: Unpin, K: Unpin,

§

impl<K, E, Formed, Context, End> UnwindSafe for HashMapSubformer<K, E, Formed, Context, End>
where Context: UnwindSafe, E: UnwindSafe, End: UnwindSafe, Formed: UnwindSafe, K: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<S> AssignWithType for S

source§

fn assign_with_type<T, IntoT>(&mut self, component: IntoT)
where IntoT: Into<T>, S: ComponentAssign<T, IntoT>,

Function to set value of a component by its type.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.