pub trait NameBuilder: Debug + Any {
// Required methods
fn finish(&self) -> Name;
fn merge(&mut self, other: &dyn NameBuilder);
fn clone_boxed(&self) -> Box<dyn NameBuilder>;
fn has_name(&self) -> bool;
fn has_extension(&self) -> bool;
fn set_name(&mut self, name: String);
fn set_with_id(&mut self, value: bool);
fn set_generated(&mut self, value: bool);
fn add_extension(&mut self, replace: bool, extension: String);
fn strip_suffix(&mut self, suffix: &str);
fn generate_unique_id(&mut self);
}Expand description
This trait defines a builder for building type names.
The general idea of the builder is the following:
- A type name needs a name to be valid. The name is set by
set_name. - The name can be extended by multiple prefixes using
add_extension. - Sometimes is it not possible to create a unique name. To get one
the builder should add a unique id to the name (this is controlled by
set_with_id). - The output of the name builder is a
Name.Names can be fixed or generated. The name builder should decide automatically which variant of the name has to be generated, if not explicitly specified by the user (usingset_generated).
Required Methods§
Sourcefn finish(&self) -> Name
fn finish(&self) -> Name
Finish the current name building and create a Name from the known
information.
Sourcefn merge(&mut self, other: &dyn NameBuilder)
fn merge(&mut self, other: &dyn NameBuilder)
Merge the data of the other name builder into the current name builder.
The passed name builder is of the same type then the current one.
Sourcefn clone_boxed(&self) -> Box<dyn NameBuilder>
fn clone_boxed(&self) -> Box<dyn NameBuilder>
Create a clone of the current builder and return it as box.
Sourcefn has_extension(&self) -> bool
fn has_extension(&self) -> bool
Returns true if this builder has at least on extension set, false otherwise.
Sourcefn set_with_id(&mut self, value: bool)
fn set_with_id(&mut self, value: bool)
Instruct the builder to add a unique id to the generated name or not.
Sourcefn set_generated(&mut self, value: bool)
fn set_generated(&mut self, value: bool)
Instruct the builder to generated a Name::Generated if true is passed,
or a Name::Named if false is passed.
Sourcefn add_extension(&mut self, replace: bool, extension: String)
fn add_extension(&mut self, replace: bool, extension: String)
Add a new extension to the builder. If replace is set to true, any previous
extension is dropped.
Sourcefn strip_suffix(&mut self, suffix: &str)
fn strip_suffix(&mut self, suffix: &str)
Remove the specified suffix from the name and the extensions.
Sourcefn generate_unique_id(&mut self)
fn generate_unique_id(&mut self)
Force the builder to generate a unique id, that is later used to generate the name.
Normally the id should be generated as last step (in the
finish method), but sometimes it is useful to
force the builder to generate the id to shared it between different copies
of the builder.
Trait Implementations§
Source§impl NameBuilder for Box<dyn NameBuilder>
impl NameBuilder for Box<dyn NameBuilder>
Source§fn finish(&self) -> Name
fn finish(&self) -> Name
Name from the known
information.Source§fn merge(&mut self, other: &dyn NameBuilder)
fn merge(&mut self, other: &dyn NameBuilder)
other name builder into the current name builder.
The passed name builder is of the same type then the current one.Source§fn clone_boxed(&self) -> Box<dyn NameBuilder>
fn clone_boxed(&self) -> Box<dyn NameBuilder>
Source§fn has_extension(&self) -> bool
fn has_extension(&self) -> bool
true if this builder has at least on extension set, false otherwise.Source§fn set_with_id(&mut self, value: bool)
fn set_with_id(&mut self, value: bool)
Source§fn set_generated(&mut self, value: bool)
fn set_generated(&mut self, value: bool)
Name::Generated if true is passed,
or a Name::Named if false is passed.Source§fn add_extension(&mut self, replace: bool, extension: String)
fn add_extension(&mut self, replace: bool, extension: String)
extension to the builder. If replace is set to true, any previous
extension is dropped.Source§fn strip_suffix(&mut self, suffix: &str)
fn strip_suffix(&mut self, suffix: &str)
suffix from the name and the extensions.Source§fn generate_unique_id(&mut self)
fn generate_unique_id(&mut self)
Source§impl NameFallback for &dyn NameBuilder
impl NameFallback for &dyn NameBuilder
Source§fn apply(self, builder: &mut dyn NameBuilder)
fn apply(self, builder: &mut dyn NameBuilder)
builder.Source§impl NameFallback for Box<dyn NameBuilder>
impl NameFallback for Box<dyn NameBuilder>
Source§fn apply(self, builder: &mut dyn NameBuilder)
fn apply(self, builder: &mut dyn NameBuilder)
builder.