pub struct FieldBuilder<'a, P> { /* private fields */ }
Expand description
A builder for struct or enum variant fields.
Implementations§
Source§impl<P> FieldBuilder<'_, P>
impl<P> FieldBuilder<'_, P>
Sourcepub fn with_attribute(
&mut self,
name: impl AsRef<str>,
value: impl FnOnce(&mut StreamBuilder) -> Result,
) -> Result<&mut Self>
pub fn with_attribute( &mut self, name: impl AsRef<str>, value: impl FnOnce(&mut StreamBuilder) -> Result, ) -> Result<&mut Self>
Add an attribute to the field.
generator
.generate_struct("Foo")
.add_field("foo", "u16")
.make_pub()
.with_attribute("serde", |b| {
b.push_parsed("(default)")?;
Ok(())
})?;
generator
.generate_enum("Bar")
.add_value("Baz")
.add_field("baz", "bool")
.with_attribute("serde", |b| {
b.push_parsed("(default)")?;
Ok(())
})?;
enum Bar { Baz { # [serde (default)] baz : bool , } , }");
Generates:
ⓘ
struct Foo {
#[serde(default)]
pub bar: u16
}
enum Bar {
Baz {
#[serde(default)]
baz: bool
}
}
Sourcepub fn with_parsed_attribute(
&mut self,
attribute: impl AsRef<str>,
) -> Result<&mut Self>
pub fn with_parsed_attribute( &mut self, attribute: impl AsRef<str>, ) -> Result<&mut Self>
Add a parsed attribute to the field.
generator
.generate_struct("Foo")
.add_field("foo", "u16")
.make_pub()
.with_parsed_attribute("serde(default)")?;
generator
.generate_enum("Bar")
.add_value("Baz")
.add_field("baz", "bool")
.with_parsed_attribute("serde(default)")?;
enum Bar { Baz { # [serde (default)] baz : bool , } , }");
Generates:
ⓘ
struct Foo {
#[serde(default)]
pub bar: u16
}
enum Bar {
Baz {
#[serde(default)]
baz: bool
}
}
Sourcepub fn with_attribute_stream(
&mut self,
attribute: impl Into<TokenStream>,
) -> &mut Self
pub fn with_attribute_stream( &mut self, attribute: impl Into<TokenStream>, ) -> &mut Self
Add a token stream as an attribute to the field.
let attribute = "serde(default)".parse::<TokenStream>().unwrap();
generator
.generate_struct("Foo")
.add_field("foo", "u16")
.make_pub()
.with_attribute_stream(attribute);
Generates:
ⓘ
struct Foo {
#[serde(default)]
pub bar: u16
}
Trait Implementations§
Auto Trait Implementations§
impl<'a, P> Freeze for FieldBuilder<'a, P>
impl<'a, P> RefUnwindSafe for FieldBuilder<'a, P>where
P: RefUnwindSafe,
impl<'a, P> !Send for FieldBuilder<'a, P>
impl<'a, P> !Sync for FieldBuilder<'a, P>
impl<'a, P> Unpin for FieldBuilder<'a, P>where
P: Unpin,
impl<'a, P> !UnwindSafe for FieldBuilder<'a, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more