Struct former::VectorSubformer

source ·
pub struct VectorSubformer<E, Container, Context, ContainerEnd>
where Container: VectorLike<E> + Default, ContainerEnd: ToSuperFormer<Container, Context>,
{ /* private fields */ }
Expand description

A builder for constructing VectorLike containers, facilitating a fluent and flexible interface.

VectorSubformer leverages the VectorLike trait to enable the construction and manipulation of vector-like containers in a builder pattern style, promoting readability and ease of use.

§Example

#[ derive( Debug, PartialEq, former::Former ) ]
pub struct StructWithVec
{
  #[ subformer( former::VectorSubformer ) ]
  vec : Vec< &'static str >,
}

let instance = StructWithVec::former()
.vec()
  .push( "apple" )
  .push( "banana" )
  .end()
.form();

assert_eq!( instance, StructWithVec { vec: vec![ "apple", "banana" ] } );

Implementations§

source§

impl<E, Container, Context, ContainerEnd> VectorSubformer<E, Container, Context, ContainerEnd>
where Container: VectorLike<E> + Default, ContainerEnd: ToSuperFormer<Container, Context>,

source

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

Initializes a new VectorSubformer instance, starting with an empty container. This function serves as the entry point for the builder pattern.

§Returns

A new instance of VectorSubformer with an empty internal container.

source

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

Begins the building process, optionally initializing with a context and container.

source

pub fn end(self) -> Context

Finalizes the building process, returning the container or a context incorporating it.

source

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

Replaces the current container with a provided one, allowing for a reset or redirection of the building process.

source§

impl<E, Container, Context, ContainerEnd> VectorSubformer<E, Container, Context, ContainerEnd>
where Container: VectorLike<E> + Default, ContainerEnd: ToSuperFormer<Container, Context>,

source

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

Appends an element to the end of the container, expanding the internal collection.

Trait Implementations§

source§

impl<E: Debug, Container, Context: Debug, ContainerEnd> Debug for VectorSubformer<E, Container, Context, ContainerEnd>
where Container: VectorLike<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: Default, Container, Context: Default, ContainerEnd> Default for VectorSubformer<E, Container, Context, ContainerEnd>
where Container: VectorLike<E> + Default + Default, ContainerEnd: ToSuperFormer<Container, Context> + Default,

source§

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

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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