pub struct HashSetSubformer<E, Container, Context, ContainerEnd>
where E: Eq + Hash, Container: HashSetLike<E> + Default, ContainerEnd: ToSuperFormer<Container, Context>,
{ /* private fields */ }
Expand description

Facilitates building HashSetLike containers with a fluent API.

HashSetSubformer leverages the HashSetLike trait to enable a concise and expressive way of populating HashSet-like containers. It exemplifies the crate’s builder pattern variation for sets.

§Example Usage

Using HashSetSubformer to populate a HashSet within a struct:


#[ derive( Debug, PartialEq, former::Former ) ]
pub struct StructWithSet
{
  #[ subformer( former::HashSetSubformer ) ]
  set : std::collections::HashSet< &'static str >,
}

let instance = StructWithSet::former()
.set()
  .insert( "apple" )
  .insert( "banana" )
  .end()
.form();

assert_eq!(instance, StructWithSet { set : hset![ "apple", "banana" ] });

Implementations§

source§

impl<E, Container, Context, ContainerEnd> HashSetSubformer<E, Container, Context, ContainerEnd>
where E: Eq + Hash, Container: HashSetLike<E> + Default, ContainerEnd: ToSuperFormer<Container, Context>,

source

pub fn new( ) -> HashSetSubformer<E, Container, Container, impl ToSuperFormer<Container, Container>>

Initializes a new instance of the builder with default settings.

This method provides a starting point for building a HashSetLike container using a fluent interface. It sets up an empty container ready to be populated.

§Returns

A new instance of HashSetSubformer with no elements.

source

pub fn begin( context: Option<Context>, container: Option<Container>, on_end: ContainerEnd ) -> Self

Begins the building process with an optional context and container.

This method is typically called internally by the builder but can be used directly to initialize the builder with specific contexts or containers.

§Parameters
  • context: An optional context for the building process.
  • container: An optional initial container to populate.
  • on_end: A handler to be called at the end of the building process.
source

pub fn end(self) -> Context

Finalizes the building process and returns the constructed container or a context.

This method concludes the building process by applying the on_end handler to transform the container or incorporate it into a given context. It’s typically called at the end of the builder chain to retrieve the final product of the building process.

§Returns

Depending on the on_end handler’s implementation, this method can return either the constructed container or a context that incorporates the container.

source

pub fn replace(self, container: Container) -> Self

Replaces the current container with a new one.

This method allows for replacing the entire set being built with a different one. It can be useful in scenarios where a pre-populated set needs to be modified or replaced entirely during the building process.

§Parameters
  • container: The new container to use for subsequent builder operations.
§Returns

The builder instance with the container replaced, enabling further chained operations.

source§

impl<E, Container, Context, ContainerEnd> HashSetSubformer<E, Container, Context, ContainerEnd>
where E: Eq + Hash, Container: HashSetLike<E> + Default, ContainerEnd: ToSuperFormer<Container, Context>,

source

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

Inserts an element into the set, possibly replacing an existing element.

This method ensures that the set contains the given element, and if the element was already present, it might replace it depending on the container’s behavior.

§Parameters
  • e: The element to insert into the set.
§Returns
  • Some(e) if the element was replaced.
  • None if the element was newly inserted without replacing any existing element. #[ inline( always ) ]

Trait Implementations§

source§

impl<E, Container, Context: Debug, ContainerEnd> Debug for HashSetSubformer<E, Container, Context, ContainerEnd>
where E: Eq + Hash + Debug, Container: HashSetLike<E> + Default + Debug, ContainerEnd: ToSuperFormer<Container, Context> + Debug,

source§

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

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

impl<E, Container, Context: Default, ContainerEnd> Default for HashSetSubformer<E, Container, Context, ContainerEnd>
where E: Eq + Hash + Default, Container: HashSetLike<E> + Default + Default, ContainerEnd: ToSuperFormer<Container, Context> + Default,

source§

fn default() -> HashSetSubformer<E, Container, Context, ContainerEnd>

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

Auto Trait Implementations§

§

impl<E, Container, Context, ContainerEnd> RefUnwindSafe for HashSetSubformer<E, Container, Context, ContainerEnd>
where Container: RefUnwindSafe, ContainerEnd: RefUnwindSafe, Context: RefUnwindSafe, E: RefUnwindSafe,

§

impl<E, Container, Context, ContainerEnd> Send for HashSetSubformer<E, Container, Context, ContainerEnd>
where Container: Send, ContainerEnd: Send, Context: Send, E: Send,

§

impl<E, Container, Context, ContainerEnd> Sync for HashSetSubformer<E, Container, Context, ContainerEnd>
where Container: Sync, ContainerEnd: Sync, Context: Sync, E: Sync,

§

impl<E, Container, Context, ContainerEnd> Unpin for HashSetSubformer<E, Container, Context, ContainerEnd>
where Container: Unpin, ContainerEnd: Unpin, Context: Unpin, E: Unpin,

§

impl<E, Container, Context, ContainerEnd> UnwindSafe for HashSetSubformer<E, Container, Context, ContainerEnd>
where Container: UnwindSafe, ContainerEnd: UnwindSafe, Context: UnwindSafe, E: 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<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.