cvars

Macro cvars 

Source
cvars!() { /* proc-macro */ }
Expand description

Generate the Cvars struct and its impls. Each cvar and its default value is defined on one line. This is the recommended way of using this crate.

All types used as cvars have to impl FromStr and Display.

§Generated code

The macro generates:

  • the struct definition
  • impl Default for Cvars which sets the initial values
  • impl Cvars with methods for interacting with cvars

The generated methods:

  • get_string - take cvar name as string and return its value as a String
  • set_str - take cvar name as string and its new value as a &str
  • get - take cvar name as string and return its value as the correct type
  • set - take cvar name as string and its new value as the correct type

See your IDE or the SetGet trait for their exact signatures.

§Example

use cvars::cvars;

cvars! {
    g_rocket_launcher_ammo_max: i32 = 20,
    g_rocket_launcher_damage: f32 = 75.0,
}

§Attributes and doc-comments

To add attributes or doc-comments to the generated struct, use inner attributes and inner comments.

use cvars::cvars;

cvars! {
    //! Documentation for the generated struct

    #![derive(Debug, Clone)]
    #![cvars(sorted)]

    /// Documentation for the cvar
    cl_projectile_render_distance: f64 = 2048.0,
}

Use #![cvars(sorted)] to check the cvars are in lexicographic order. If not, the macro will panic as there’s currently no way to emit a warning from proc macros.