NameBuilder

Trait NameBuilder 

Source
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 (using set_generated).

Required Methods§

Source

fn finish(&self) -> Name

Finish the current name building and create a Name from the known information.

Source

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.

Source

fn clone_boxed(&self) -> Box<dyn NameBuilder>

Create a clone of the current builder and return it as box.

Source

fn has_name(&self) -> bool

Returns true if this builder has a name set, false otherwise.

Source

fn has_extension(&self) -> bool

Returns true if this builder has at least on extension set, false otherwise.

Source

fn set_name(&mut self, name: String)

Set the base name of this builder.

Source

fn set_with_id(&mut self, value: bool)

Instruct the builder to add a unique id to the generated name or not.

Source

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.

Source

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.

Source

fn strip_suffix(&mut self, suffix: &str)

Remove the specified suffix from the name and the extensions.

Source

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>

Source§

fn finish(&self) -> Name

Finish the current name building and create a Name from the known information.
Source§

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.
Source§

fn clone_boxed(&self) -> Box<dyn NameBuilder>

Create a clone of the current builder and return it as box.
Source§

fn has_name(&self) -> bool

Returns true if this builder has a name set, false otherwise.
Source§

fn has_extension(&self) -> bool

Returns true if this builder has at least on extension set, false otherwise.
Source§

fn set_name(&mut self, name: String)

Set the base name of this builder.
Source§

fn set_with_id(&mut self, value: bool)

Instruct the builder to add a unique id to the generated name or not.
Source§

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.
Source§

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.
Source§

fn strip_suffix(&mut self, suffix: &str)

Remove the specified suffix from the name and the extensions.
Source§

fn generate_unique_id(&mut self)

Force the builder to generate a unique id, that is later used to generate the name. Read more
Source§

impl NameFallback for &dyn NameBuilder

Source§

fn apply(self, builder: &mut dyn NameBuilder)

Apply the fallback to the passed builder.
Source§

impl NameFallback for Box<dyn NameBuilder>

Source§

fn apply(self, builder: &mut dyn NameBuilder)

Apply the fallback to the passed builder.

Implementations on Foreign Types§

Source§

impl NameBuilder for Box<dyn NameBuilder>

Source§

fn finish(&self) -> Name

Source§

fn merge(&mut self, other: &dyn NameBuilder)

Source§

fn clone_boxed(&self) -> Box<dyn NameBuilder>

Source§

fn has_name(&self) -> bool

Source§

fn has_extension(&self) -> bool

Source§

fn set_name(&mut self, name: String)

Source§

fn set_with_id(&mut self, value: bool)

Source§

fn set_generated(&mut self, value: bool)

Source§

fn add_extension(&mut self, replace: bool, extension: String)

Source§

fn strip_suffix(&mut self, suffix: &str)

Source§

fn generate_unique_id(&mut self)

Implementors§