pub struct FieldsHelper<'f, T: FieldInfo> { /* private fields */ }
Expand description

Utility struct to work with [Fields]

Implementations§

source§

impl<'f, T: FieldInfo> FieldsHelper<'f, T>

source

pub fn new(fields: &'f Fields<T>) -> Self

Builds a new FieldsHelper

source

pub fn filtering<P>(self, predicate: P) -> Self
where P: Fn(usize, &T) -> bool + 'f,

Remove all fields f for which predicate(&f) returns false. This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.

source

pub fn with_attributes<P>(self, predicate: P) -> Self
where P: Fn(usize, &T) -> Option<TokenStream> + 'f,

Adds an arbitrary number of attributes to each field.

source

pub fn include_default<'a>( self, include_default: impl IntoIterator<Item = &'a Ident> ) -> Self

Includes default fields by including , field1: Default::default() , field2: Default::default() at the end.

It’s only used on named fields, but ignored for tuples.

source

pub fn include_default_with<'a>( self, include_default: impl IntoIterator<Item = (&'a Ident, impl ToTokens)> ) -> Self

Includes default fields by including , field1: expr1 , field2: expr2 at the end.

It’s only used on named fields, but ignored for tuples.

source

pub fn include_all_default(self, include_all_default: bool) -> Self

Wether to include , ..Default::default() at the end or not, defaults to false.

source

pub fn ignore_extra<'a>( self, ignore_extra: impl IntoIterator<Item = &'a Ident> ) -> Self

Ignore extra fields by including , field1: _ , field2: _ at the end.

It’s only used on named fields, but ignored for tuples.

source

pub fn ignore_all_extra(self, ignore_all_extra: bool) -> Self

Wether to include , .. at the end or not, defaults to false.

source

pub fn include_visibility(self, include_visibility: bool) -> Self

Wether to include the visibility at the beginning or not, defaults to false.

source

pub fn left_collector<C>(self, left_collector: C) -> Self
where C: FnMut(usize, &T) -> TokenStream + 'f,

Specifies the left collector. It’s only used with named fields.

Defaults to FieldsCollector::ident

source

pub fn right_collector<C>(self, right_collector: C) -> Self
where C: FnMut(usize, &T) -> TokenStream + 'f,

Specifies the right collector.

Defaults to FieldsCollector::ty

source

pub fn is_empty(&self) -> bool

Checks if there’s no fields

source

pub fn into_vec(self) -> Vec<&'f T>

Takes the inner fields

source

pub fn collect(self) -> TokenStream

Collects the fields.

Examples

If using the default collectors on a Struct:

{
    field_1: String,
    field_2: i32,
}

If using FieldsCollector::ident right collector on a Struct:

{
    field_1: field_1,
    field_2: field_2,
}

Auto Trait Implementations§

§

impl<'f, T> !RefUnwindSafe for FieldsHelper<'f, T>

§

impl<'f, T> !Send for FieldsHelper<'f, T>

§

impl<'f, T> !Sync for FieldsHelper<'f, T>

§

impl<'f, T> Unpin for FieldsHelper<'f, T>

§

impl<'f, T> !UnwindSafe for FieldsHelper<'f, T>

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.