pub trait CompileConst {
    // Required methods
    fn const_type() -> String;
    fn const_val(&self) -> String;

    // Provided methods
    fn declaration(
        &self,
        attrs: &str,
        vis: &str,
        declaration_type: DeclarationType,
        name: &str
    ) -> String { ... }
    fn const_declaration(&self, attrs: &str, vis: &str, name: &str) -> String { ... }
    fn static_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§

source

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.

source

fn const_val(&self) -> String

Get a string representation of the current value in constant form.

Provided Methods§

source

fn declaration( &self, attrs: &str, vis: &str, declaration_type: DeclarationType, name: &str ) -> String

Generates the declaration statement string.

Takes 3 strings: Attributes, a visibility (eg pub) and a name (a SCREAMING_SNAKE_CASE string is preferred), plus a declaration type (e.g. const or static).

It then constructs a valid Rust declaration statement using the type and value of the current object by calling const_val() and const_type().

 use const_gen::{CompileConst, DeclarationType};

 let test_str_declaration = "I'm a string!".declaration(
    "#[allow(dead_code)]",
    "pub(crate)",
    DeclarationType::Const,
    "TEST_STR",
 );
 assert_eq!(
    test_str_declaration,
    r#"#[allow(dead_code)] pub(crate) const TEST_STR: &str = "I'm a string!";"#
 );
source

fn const_declaration(&self, attrs: &str, vis: &str, name: &str) -> String

Generates the declaration statement string for a const declaration.

See declaration() for more information.

source

fn static_declaration(&self, attrs: &str, vis: &str, name: &str) -> String

Generates the declaration statement string for a static declaration.

See declaration() for more information.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl CompileConst for &str

source§

impl CompileConst for bool

source§

impl CompileConst for f32

source§

impl CompileConst for f64

source§

impl CompileConst for i8

source§

impl CompileConst for i16

source§

impl CompileConst for i32

source§

impl CompileConst for i64

source§

impl CompileConst for i128

source§

impl CompileConst for isize

source§

impl CompileConst for str

source§

impl CompileConst for u8

source§

impl CompileConst for u16

source§

impl CompileConst for u32

source§

impl CompileConst for u64

source§

impl CompileConst for u128

source§

impl CompileConst for ()

source§

impl CompileConst for usize

source§

impl CompileConst for String

source§

impl<A: CompileConst, B: CompileConst> CompileConst for (A, B)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst> CompileConst for (A, B, C)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst> CompileConst for (A, B, C, D)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst> CompileConst for (A, B, C, D, E)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst> CompileConst for (A, B, C, D, E, F)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst> CompileConst for (A, B, C, D, E, F, G)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst> CompileConst for (A, B, C, D, E, F, G, H)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst, I: CompileConst> CompileConst for (A, B, C, D, E, F, G, H, I)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst, I: CompileConst, J: CompileConst> CompileConst for (A, B, C, D, E, F, G, H, I, J)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst, I: CompileConst, J: CompileConst, K: CompileConst> CompileConst for (A, B, C, D, E, F, G, H, I, J, K)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst, I: CompileConst, J: CompileConst, K: CompileConst, L: CompileConst> CompileConst for (A, B, C, D, E, F, G, H, I, J, K, L)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst, I: CompileConst, J: CompileConst, K: CompileConst, L: CompileConst, M: CompileConst> CompileConst for (A, B, C, D, E, F, G, H, I, J, K, L, M)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst, I: CompileConst, J: CompileConst, K: CompileConst, L: CompileConst, M: CompileConst, N: CompileConst> CompileConst for (A, B, C, D, E, F, G, H, I, J, K, L, M, N)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst, I: CompileConst, J: CompileConst, K: CompileConst, L: CompileConst, M: CompileConst, N: CompileConst, O: CompileConst> CompileConst for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)

source§

impl<A: CompileConst, B: CompileConst, C: CompileConst, D: CompileConst, E: CompileConst, F: CompileConst, G: CompileConst, H: CompileConst, I: CompileConst, J: CompileConst, K: CompileConst, L: CompileConst, M: CompileConst, N: CompileConst, O: CompileConst, P: CompileConst> CompileConst for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)

source§

impl<E: CompileConst> CompileConst for HashSet<E>

source§

impl<K: CompileConst, V: CompileConst> CompileConst for HashMap<K, V>

source§

impl<T: CompileConst + Clone> CompileConst for Cow<'_, T>

source§

impl<T: CompileConst> CompileConst for &[T]

source§

impl<T: CompileConst> CompileConst for Option<T>

source§

impl<T: CompileConst> CompileConst for [T; 0]

source§

impl<T: CompileConst> CompileConst for [T; 1]

source§

impl<T: CompileConst> CompileConst for [T; 2]

source§

impl<T: CompileConst> CompileConst for [T; 3]

source§

impl<T: CompileConst> CompileConst for [T; 4]

source§

impl<T: CompileConst> CompileConst for [T; 5]

source§

impl<T: CompileConst> CompileConst for [T; 6]

source§

impl<T: CompileConst> CompileConst for [T; 7]

source§

impl<T: CompileConst> CompileConst for [T; 8]

source§

impl<T: CompileConst> CompileConst for [T; 9]

source§

impl<T: CompileConst> CompileConst for [T; 10]

source§

impl<T: CompileConst> CompileConst for [T; 11]

source§

impl<T: CompileConst> CompileConst for [T; 12]

source§

impl<T: CompileConst> CompileConst for [T; 13]

source§

impl<T: CompileConst> CompileConst for [T; 14]

source§

impl<T: CompileConst> CompileConst for [T; 15]

source§

impl<T: CompileConst> CompileConst for [T; 16]

source§

impl<T: CompileConst> CompileConst for [T; 17]

source§

impl<T: CompileConst> CompileConst for [T; 18]

source§

impl<T: CompileConst> CompileConst for [T; 19]

source§

impl<T: CompileConst> CompileConst for [T; 20]

source§

impl<T: CompileConst> CompileConst for [T; 21]

source§

impl<T: CompileConst> CompileConst for [T; 22]

source§

impl<T: CompileConst> CompileConst for [T; 23]

source§

impl<T: CompileConst> CompileConst for [T; 24]

source§

impl<T: CompileConst> CompileConst for [T; 25]

source§

impl<T: CompileConst> CompileConst for [T; 26]

source§

impl<T: CompileConst> CompileConst for [T; 27]

source§

impl<T: CompileConst> CompileConst for [T; 28]

source§

impl<T: CompileConst> CompileConst for [T; 29]

source§

impl<T: CompileConst> CompileConst for [T; 30]

source§

impl<T: CompileConst> CompileConst for [T; 31]

source§

impl<T: CompileConst> CompileConst for [T; 32]

source§

impl<T: CompileConst> CompileConst for [T; 33]

source§

impl<T: CompileConst> CompileConst for [T; 34]

source§

impl<T: CompileConst> CompileConst for [T; 35]

source§

impl<T: CompileConst> CompileConst for [T; 36]

source§

impl<T: CompileConst> CompileConst for [T; 37]

source§

impl<T: CompileConst> CompileConst for [T; 38]

source§

impl<T: CompileConst> CompileConst for [T; 39]

source§

impl<T: CompileConst> CompileConst for [T; 40]

source§

impl<T: CompileConst> CompileConst for [T; 41]

source§

impl<T: CompileConst> CompileConst for [T; 42]

source§

impl<T: CompileConst> CompileConst for [T; 43]

source§

impl<T: CompileConst> CompileConst for [T; 44]

source§

impl<T: CompileConst> CompileConst for [T; 45]

source§

impl<T: CompileConst> CompileConst for [T; 46]

source§

impl<T: CompileConst> CompileConst for [T; 47]

source§

impl<T: CompileConst> CompileConst for [T; 48]

source§

impl<T: CompileConst> CompileConst for [T; 49]

source§

impl<T: CompileConst> CompileConst for [T; 50]

source§

impl<T: CompileConst> CompileConst for [T; 51]

source§

impl<T: CompileConst> CompileConst for [T; 52]

source§

impl<T: CompileConst> CompileConst for [T; 53]

source§

impl<T: CompileConst> CompileConst for [T; 54]

source§

impl<T: CompileConst> CompileConst for [T; 55]

source§

impl<T: CompileConst> CompileConst for [T; 56]

source§

impl<T: CompileConst> CompileConst for [T; 57]

source§

impl<T: CompileConst> CompileConst for [T; 58]

source§

impl<T: CompileConst> CompileConst for [T; 59]

source§

impl<T: CompileConst> CompileConst for [T; 60]

source§

impl<T: CompileConst> CompileConst for [T; 61]

source§

impl<T: CompileConst> CompileConst for [T; 62]

source§

impl<T: CompileConst> CompileConst for [T; 63]

source§

impl<T: CompileConst> CompileConst for [T; 64]

source§

impl<T: CompileConst> CompileConst for [T; 65]

source§

impl<T: CompileConst> CompileConst for [T; 66]

source§

impl<T: CompileConst> CompileConst for [T; 67]

source§

impl<T: CompileConst> CompileConst for [T; 68]

source§

impl<T: CompileConst> CompileConst for [T; 69]

source§

impl<T: CompileConst> CompileConst for [T; 70]

source§

impl<T: CompileConst> CompileConst for [T; 71]

source§

impl<T: CompileConst> CompileConst for [T; 72]

source§

impl<T: CompileConst> CompileConst for [T; 73]

source§

impl<T: CompileConst> CompileConst for [T; 74]

source§

impl<T: CompileConst> CompileConst for [T; 75]

source§

impl<T: CompileConst> CompileConst for [T; 76]

source§

impl<T: CompileConst> CompileConst for [T; 77]

source§

impl<T: CompileConst> CompileConst for [T; 78]

source§

impl<T: CompileConst> CompileConst for [T; 79]

source§

impl<T: CompileConst> CompileConst for [T; 80]

source§

impl<T: CompileConst> CompileConst for [T; 81]

source§

impl<T: CompileConst> CompileConst for [T; 82]

source§

impl<T: CompileConst> CompileConst for [T; 83]

source§

impl<T: CompileConst> CompileConst for [T; 84]

source§

impl<T: CompileConst> CompileConst for [T; 85]

source§

impl<T: CompileConst> CompileConst for [T; 86]

source§

impl<T: CompileConst> CompileConst for [T; 87]

source§

impl<T: CompileConst> CompileConst for [T; 88]

source§

impl<T: CompileConst> CompileConst for [T; 89]

source§

impl<T: CompileConst> CompileConst for [T; 90]

source§

impl<T: CompileConst> CompileConst for [T; 91]

source§

impl<T: CompileConst> CompileConst for [T; 92]

source§

impl<T: CompileConst> CompileConst for [T; 93]

source§

impl<T: CompileConst> CompileConst for [T; 94]

source§

impl<T: CompileConst> CompileConst for [T; 95]

source§

impl<T: CompileConst> CompileConst for [T; 96]

source§

impl<T: CompileConst> CompileConst for [T; 97]

source§

impl<T: CompileConst> CompileConst for [T; 98]

source§

impl<T: CompileConst> CompileConst for [T; 99]

source§

impl<T: CompileConst> CompileConst for [T; 100]

source§

impl<T: CompileConst> CompileConst for [T; 101]

source§

impl<T: CompileConst> CompileConst for [T; 102]

source§

impl<T: CompileConst> CompileConst for [T; 103]

source§

impl<T: CompileConst> CompileConst for [T; 104]

source§

impl<T: CompileConst> CompileConst for [T; 105]

source§

impl<T: CompileConst> CompileConst for [T; 106]

source§

impl<T: CompileConst> CompileConst for [T; 107]

source§

impl<T: CompileConst> CompileConst for [T; 108]

source§

impl<T: CompileConst> CompileConst for [T; 109]

source§

impl<T: CompileConst> CompileConst for [T; 110]

source§

impl<T: CompileConst> CompileConst for [T; 111]

source§

impl<T: CompileConst> CompileConst for [T; 112]

source§

impl<T: CompileConst> CompileConst for [T; 113]

source§

impl<T: CompileConst> CompileConst for [T; 114]

source§

impl<T: CompileConst> CompileConst for [T; 115]

source§

impl<T: CompileConst> CompileConst for [T; 116]

source§

impl<T: CompileConst> CompileConst for [T; 117]

source§

impl<T: CompileConst> CompileConst for [T; 118]

source§

impl<T: CompileConst> CompileConst for [T; 119]

source§

impl<T: CompileConst> CompileConst for [T; 120]

source§

impl<T: CompileConst> CompileConst for [T; 121]

source§

impl<T: CompileConst> CompileConst for [T; 122]

source§

impl<T: CompileConst> CompileConst for [T; 123]

source§

impl<T: CompileConst> CompileConst for [T; 124]

source§

impl<T: CompileConst> CompileConst for [T; 125]

source§

impl<T: CompileConst> CompileConst for [T; 126]

source§

impl<T: CompileConst> CompileConst for [T; 127]

source§

impl<T: CompileConst> CompileConst for [T; 128]

source§

impl<T: CompileConst> CompileConst for [T; 129]

source§

impl<T: CompileConst> CompileConst for [T; 130]

source§

impl<T: CompileConst> CompileConst for [T; 131]

source§

impl<T: CompileConst> CompileConst for [T; 132]

source§

impl<T: CompileConst> CompileConst for [T; 133]

source§

impl<T: CompileConst> CompileConst for [T; 134]

source§

impl<T: CompileConst> CompileConst for [T; 135]

source§

impl<T: CompileConst> CompileConst for [T; 136]

source§

impl<T: CompileConst> CompileConst for [T; 137]

source§

impl<T: CompileConst> CompileConst for [T; 138]

source§

impl<T: CompileConst> CompileConst for [T; 139]

source§

impl<T: CompileConst> CompileConst for [T; 140]

source§

impl<T: CompileConst> CompileConst for [T; 141]

source§

impl<T: CompileConst> CompileConst for [T; 142]

source§

impl<T: CompileConst> CompileConst for [T; 143]

source§

impl<T: CompileConst> CompileConst for [T; 144]

source§

impl<T: CompileConst> CompileConst for [T; 145]

source§

impl<T: CompileConst> CompileConst for [T; 146]

source§

impl<T: CompileConst> CompileConst for [T; 147]

source§

impl<T: CompileConst> CompileConst for [T; 148]

source§

impl<T: CompileConst> CompileConst for [T; 149]

source§

impl<T: CompileConst> CompileConst for [T; 150]

source§

impl<T: CompileConst> CompileConst for [T; 151]

source§

impl<T: CompileConst> CompileConst for [T; 152]

source§

impl<T: CompileConst> CompileConst for [T; 153]

source§

impl<T: CompileConst> CompileConst for [T; 154]

source§

impl<T: CompileConst> CompileConst for [T; 155]

source§

impl<T: CompileConst> CompileConst for [T; 156]

source§

impl<T: CompileConst> CompileConst for [T; 157]

source§

impl<T: CompileConst> CompileConst for [T; 158]

source§

impl<T: CompileConst> CompileConst for [T; 159]

source§

impl<T: CompileConst> CompileConst for [T; 160]

source§

impl<T: CompileConst> CompileConst for [T; 161]

source§

impl<T: CompileConst> CompileConst for [T; 162]

source§

impl<T: CompileConst> CompileConst for [T; 163]

source§

impl<T: CompileConst> CompileConst for [T; 164]

source§

impl<T: CompileConst> CompileConst for [T; 165]

source§

impl<T: CompileConst> CompileConst for [T; 166]

source§

impl<T: CompileConst> CompileConst for [T; 167]

source§

impl<T: CompileConst> CompileConst for [T; 168]

source§

impl<T: CompileConst> CompileConst for [T; 169]

source§

impl<T: CompileConst> CompileConst for [T; 170]

source§

impl<T: CompileConst> CompileConst for [T; 171]

source§

impl<T: CompileConst> CompileConst for [T; 172]

source§

impl<T: CompileConst> CompileConst for [T; 173]

source§

impl<T: CompileConst> CompileConst for [T; 174]

source§

impl<T: CompileConst> CompileConst for [T; 175]

source§

impl<T: CompileConst> CompileConst for [T; 176]

source§

impl<T: CompileConst> CompileConst for [T; 177]

source§

impl<T: CompileConst> CompileConst for [T; 178]

source§

impl<T: CompileConst> CompileConst for [T; 179]

source§

impl<T: CompileConst> CompileConst for [T; 180]

source§

impl<T: CompileConst> CompileConst for [T; 181]

source§

impl<T: CompileConst> CompileConst for [T; 182]

source§

impl<T: CompileConst> CompileConst for [T; 183]

source§

impl<T: CompileConst> CompileConst for [T; 184]

source§

impl<T: CompileConst> CompileConst for [T; 185]

source§

impl<T: CompileConst> CompileConst for [T; 186]

source§

impl<T: CompileConst> CompileConst for [T; 187]

source§

impl<T: CompileConst> CompileConst for [T; 188]

source§

impl<T: CompileConst> CompileConst for [T; 189]

source§

impl<T: CompileConst> CompileConst for [T; 190]

source§

impl<T: CompileConst> CompileConst for [T; 191]

source§

impl<T: CompileConst> CompileConst for [T; 192]

source§

impl<T: CompileConst> CompileConst for [T; 193]

source§

impl<T: CompileConst> CompileConst for [T; 194]

source§

impl<T: CompileConst> CompileConst for [T; 195]

source§

impl<T: CompileConst> CompileConst for [T; 196]

source§

impl<T: CompileConst> CompileConst for [T; 197]

source§

impl<T: CompileConst> CompileConst for [T; 198]

source§

impl<T: CompileConst> CompileConst for [T; 199]

source§

impl<T: CompileConst> CompileConst for [T; 200]

source§

impl<T: CompileConst> CompileConst for [T; 201]

source§

impl<T: CompileConst> CompileConst for [T; 202]

source§

impl<T: CompileConst> CompileConst for [T; 203]

source§

impl<T: CompileConst> CompileConst for [T; 204]

source§

impl<T: CompileConst> CompileConst for [T; 205]

source§

impl<T: CompileConst> CompileConst for [T; 206]

source§

impl<T: CompileConst> CompileConst for [T; 207]

source§

impl<T: CompileConst> CompileConst for [T; 208]

source§

impl<T: CompileConst> CompileConst for [T; 209]

source§

impl<T: CompileConst> CompileConst for [T; 210]

source§

impl<T: CompileConst> CompileConst for [T; 211]

source§

impl<T: CompileConst> CompileConst for [T; 212]

source§

impl<T: CompileConst> CompileConst for [T; 213]

source§

impl<T: CompileConst> CompileConst for [T; 214]

source§

impl<T: CompileConst> CompileConst for [T; 215]

source§

impl<T: CompileConst> CompileConst for [T; 216]

source§

impl<T: CompileConst> CompileConst for [T; 217]

source§

impl<T: CompileConst> CompileConst for [T; 218]

source§

impl<T: CompileConst> CompileConst for [T; 219]

source§

impl<T: CompileConst> CompileConst for [T; 220]

source§

impl<T: CompileConst> CompileConst for [T; 221]

source§

impl<T: CompileConst> CompileConst for [T; 222]

source§

impl<T: CompileConst> CompileConst for [T; 223]

source§

impl<T: CompileConst> CompileConst for [T; 224]

source§

impl<T: CompileConst> CompileConst for [T; 225]

source§

impl<T: CompileConst> CompileConst for [T; 226]

source§

impl<T: CompileConst> CompileConst for [T; 227]

source§

impl<T: CompileConst> CompileConst for [T; 228]

source§

impl<T: CompileConst> CompileConst for [T; 229]

source§

impl<T: CompileConst> CompileConst for [T; 230]

source§

impl<T: CompileConst> CompileConst for [T; 231]

source§

impl<T: CompileConst> CompileConst for [T; 232]

source§

impl<T: CompileConst> CompileConst for [T; 233]

source§

impl<T: CompileConst> CompileConst for [T; 234]

source§

impl<T: CompileConst> CompileConst for [T; 235]

source§

impl<T: CompileConst> CompileConst for [T; 236]

source§

impl<T: CompileConst> CompileConst for [T; 237]

source§

impl<T: CompileConst> CompileConst for [T; 238]

source§

impl<T: CompileConst> CompileConst for [T; 239]

source§

impl<T: CompileConst> CompileConst for [T; 240]

source§

impl<T: CompileConst> CompileConst for [T; 241]

source§

impl<T: CompileConst> CompileConst for [T; 242]

source§

impl<T: CompileConst> CompileConst for [T; 243]

source§

impl<T: CompileConst> CompileConst for [T; 244]

source§

impl<T: CompileConst> CompileConst for [T; 245]

source§

impl<T: CompileConst> CompileConst for [T; 246]

source§

impl<T: CompileConst> CompileConst for [T; 247]

source§

impl<T: CompileConst> CompileConst for [T; 248]

source§

impl<T: CompileConst> CompileConst for [T; 249]

source§

impl<T: CompileConst> CompileConst for [T; 250]

source§

impl<T: CompileConst> CompileConst for [T; 251]

source§

impl<T: CompileConst> CompileConst for [T; 252]

source§

impl<T: CompileConst> CompileConst for [T; 253]

source§

impl<T: CompileConst> CompileConst for [T; 254]

source§

impl<T: CompileConst> CompileConst for [T; 255]

source§

impl<T: CompileConst> CompileConst for [T; 256]

source§

impl<T: CompileConst> CompileConst for Box<T>

source§

impl<T: CompileConst> CompileConst for Rc<T>

source§

impl<T: CompileConst> CompileConst for Arc<T>

source§

impl<T: CompileConst> CompileConst for Vec<T>

Implementors§