Struct derive_builder_core::BuildMethod [−][src]
pub struct BuildMethod<'a> { pub enabled: bool, pub ident: &'a Ident, pub visibility: Visibility, pub pattern: BuilderPattern, pub target_ty: &'a Ident, pub target_ty_generics: Option<TypeGenerics<'a>>, pub initializers: Vec<TokenStream>, pub doc_comment: Option<Attribute>, pub bindings: Bindings, pub default_struct: Option<Block>, pub validate_fn: Option<&'a Path>, }
Initializer for the struct fields in the build method, implementing
quote::ToTokens
.
Examples
Will expand to something like the following (depending on settings):
pub fn build(&self) -> ::std::result::Result<Foo, ::std::string::String> { Ok(Foo { foo: self.foo, }) }
Fields
enabled: bool
Enables code generation for this build method.
ident: &'a Ident
Name of this build fn.
visibility: Visibility
Visibility of the build method, e.g. syn::Visibility::Public
.
pattern: BuilderPattern
How the build method takes and returns self
(e.g. mutably).
target_ty: &'a Ident
Type of the target field.
The corresonding builder field will be Option<field_type>
.
target_ty_generics: Option<TypeGenerics<'a>>
Type parameters and lifetimes attached to this builder struct.
initializers: Vec<TokenStream>
Field initializers for the target type.
doc_comment: Option<Attribute>
Doc-comment of the builder struct.
bindings: Bindings
Bindings to libstd or libcore.
default_struct: Option<Block>
Default value for the whole struct.
This will be in scope for all initializers as __default
.
validate_fn: Option<&'a Path>
Validation function with signature &FooBuilder -> Result<(), String>
to call before the macro-provided struct buildout.
Implementations
impl<'a> BuildMethod<'a>
[src]
impl<'a> BuildMethod<'a>
[src]pub fn doc_comment(&mut self, s: String) -> &mut Self
[src]
Set a doc-comment for this item.
pub fn push_initializer(&mut self, init: Initializer<'_>) -> &mut Self
[src]
Populate the BuildMethod
with appropriate initializers of the
underlying struct.
For each struct field this must be called with the appropriate initializer.
Trait Implementations
impl<'a> ToTokens for BuildMethod<'a>
[src]
impl<'a> ToTokens for BuildMethod<'a>
[src]