Struct former::exposed::HashMapSubformer
source · pub struct HashMapSubformer<K, E, Formed, Context, End>{ /* 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 implementEq
andHash
.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>
impl<K, E, Formed, Context, End> HashMapSubformer<K, E, Formed, Context, End>
sourcepub fn begin(
formed: Option<Formed>,
context: Option<Context>,
on_end: End
) -> Self
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§impl<K, E, Formed> HashMapSubformer<K, E, Formed, Formed, ReturnFormed>
impl<K, E, Formed> HashMapSubformer<K, E, Formed, Formed, ReturnFormed>
source§impl<K, E, Formed, Context, End> HashMapSubformer<K, E, Formed, Context, End>
impl<K, E, Formed, Context, End> HashMapSubformer<K, E, Formed, Context, End>
sourcepub fn insert<K2, E2>(self, k: K2, e: E2) -> Self
pub fn insert<K2, E2>(self, k: K2, e: E2) -> Self
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.
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,
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§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,
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>
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>
impl<K, E, Formed, Context, End> RefUnwindSafe for HashMapSubformer<K, E, Formed, Context, End>where
Context: RefUnwindSafe,
E: RefUnwindSafe,
End: RefUnwindSafe,
Formed: RefUnwindSafe,
K: RefUnwindSafe,
impl<K, E, Formed, Context, End> Send for HashMapSubformer<K, E, Formed, Context, End>
impl<K, E, Formed, Context, End> Sync for HashMapSubformer<K, E, Formed, Context, End>
impl<K, E, Formed, Context, End> Unpin for HashMapSubformer<K, E, Formed, Context, End>
impl<K, E, Formed, Context, End> UnwindSafe for HashMapSubformer<K, E, Formed, Context, End>
Blanket Implementations§
source§impl<S> AssignWithType for S
impl<S> AssignWithType for S
source§fn assign_with_type<T, IntoT>(&mut self, component: IntoT)where
IntoT: Into<T>,
S: ComponentAssign<T, IntoT>,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more