Struct FieldsHelper

Source
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 extra_default_fields<'a>( self, fields: impl IntoIterator<Item = &'a Ident>, ) -> Self

Includes additional default fields by including field1: Default::default(), field2: Default::default(),

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

Source

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

Includes additional fields by including field1: field1, field2: field2,

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

Source

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

Includes additional fields by including field1: expr1, field2: expr2.

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

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_all_default(self, include_all_default: bool) -> Self

Wether to include , ..Default::default() 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 include_wrapper(self, include_wrapper: bool) -> Self

Wether to include the wrapper (curly braces for named fields, parenthesis for tuples), defaults to true.

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> Freeze for FieldsHelper<'f, T>

§

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>,

Source§

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>,

Source§

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.