[−][src]Struct macro_input::Defs
Defs
is a collection of Def
s
Example
use macro_input::{DefaultValue, Def, Defs}; const BAR_FIELD: Def = Def::new("foo", "bar", false, DefaultValue::Bool(None)); const BAZ_FIELD: Def = Def::new("foo", "baz", false, DefaultValue::Str(None)); const FOO_FIELDS: &[&Def] = &[&BAR_FIELD, &BAZ_FIELD]; const FOO_FIELD_DEFS: Defs = Defs::new(FOO_FIELDS);
Implementations
impl<'a> Defs<'a>
[src]
#[must_use]pub const fn new(defs: &'a [&'a Def<'a>]) -> Defs<'a>
[src]
create a new collection of Def
s from a slice
#[must_use]pub const fn empty() -> &'static Defs<'static>
[src]
return an empty collection of Def
s
pub fn strip(&self, attrs: &mut Vec<Attribute, Global>)
[src]
strip away the attributes for all fields
This is useful for attribute macros because rust has no way of knowing which attributes were used.
use macro_input::{DefaultValue, Def, Defs}; use syn::{parse_quote, Attribute}; // construct some attributes let attr1: Attribute = parse_quote!(#[foo(bar = false)]); let attr2: Attribute = parse_quote!(#[foo(baz = "baz")]); let attr3: Attribute = parse_quote!(#[foo(qux = "qux", quux = 3)]); let attr4: Attribute = parse_quote!(#[foo(quuz = 'b')]); let attr5: Attribute = parse_quote!(#[some(thing = "value")]); let mut attrs = vec![attr1, attr2, attr3, attr4, attr5]; // strip away all mentions of the fields bar, baz and qux in foo const BAR_FIELD: Def = Def::new("foo", "bar", false, DefaultValue::Bool(None)); const BAZ_FIELD: Def = Def::new("foo", "baz", false, DefaultValue::Str(None)); const QUX_FIELD: Def = Def::new("foo", "qux", false, DefaultValue::Str(None)); const FOO_FIELDS: &[&Def] = &[&BAR_FIELD, &BAZ_FIELD, &QUX_FIELD]; const FOO_FIELD_DEFS: Defs = Defs::new(FOO_FIELDS); FOO_FIELD_DEFS.strip(&mut attrs); // the Vec no longer contains // #[foo(bar = false)], #[foo(baz = "baz")] and #[foo(qux = "qux")] // but // #[foo(quux = 3)], #[foo(quuz = 'b')], #[some(thing = "value")] // remain let attr1: Attribute = parse_quote!(#[foo(quux = 3)]); let attr2: Attribute = parse_quote!(#[foo(quuz = 'b')]); let attr3: Attribute = parse_quote!(#[some(thing = "value")]); assert_eq!(attrs, vec![attr1, attr2, attr3]);
Trait Implementations
impl<'a> From<&'a [&'a Def<'a>]> for Defs<'a>
[src]
impl<'_> Lint<Vec<Attribute, Global>> for Defs<'_>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for Defs<'a>
[src]
impl<'a> !Send for Defs<'a>
[src]
impl<'a> !Sync for Defs<'a>
[src]
impl<'a> Unpin for Defs<'a>
[src]
impl<'a> UnwindSafe for Defs<'a>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,