Trait const_gen::CompileConst
source · [−]pub trait CompileConst {
fn const_type() -> String;
fn const_val(&self) -> String;
fn const_declaration(&self, attrs: &str, vis: &str, name: &str) -> String { ... }
fn const_definition(_attrs: &str, _vis: &str) -> String { ... }
}Expand description
Trait which defines how a type should be represented as a constant
Required Methods
fn const_type() -> String
fn const_type() -> String
Get a string representation of a type. This must be implemented for each type. Note that this is not necessarily a representation of the ACTUAL type, but rather the type that should be used if this data is going to be represented as a compile-time constant.
Provided Methods
Takes 3 strings: Attrbibutes, a visibility (eg pub) and a name (a SCREAMING_SNAKE_CASE string is preferred) to use as a constant name, then calls self.const_type() and self.const_val() in order to generate a Rust compile-time constant declaration statement.
fn const_definition(_attrs: &str, _vis: &str) -> String
fn const_definition(_attrs: &str, _vis: &str) -> String
Return a const definition for this type. Attributes may be included, and
must be formatted as the compiler would expect to see them (including
the pound sign and square brackets "#[...]"). Always returns an empty
string for types defined in the standard library. Typically this is
easier to call instead through the const_definition! macro. Visibility
modifiers (eg, pub(…)) may be used, or an empty string passed in to
generate a private item.