Builtin placeholders
cargo-generate supports a number of builtin placeholders for use in templates.
These placeholders can be used directly in files using the Liquid language, or from Rhai scripts using the syntax:
variable::get("placeholder name")
Builtin placeholders are:
authors- this will be filled in by a function borrowed from Cargo's source code, that determines your information from
Cargo's configuration. It will either be on the form
username <email>or just plainusername.
- this will be filled in by a function borrowed from Cargo's source code, that determines your information from
Cargo's configuration. It will either be on the form
project-name- this is supplied by either passing the
--nameflag to the command or working with the interactive CLI to supply a name. It can be provided in snake_case or dash-case, in all other cases it is converted to dash-case. - it can also be supplied via the environment variable
CARGO_GENERATE_VALUE_PROJECT_NAMEwhen running in--silentmode⚠️ Note: the
--forceflag allows you to use the project name as it is given, without adjusting. Please use it carefully.
- this is supplied by either passing the
crate_name- the snake_case_version of
project-name
- the snake_case_version of
crate_type- this is supplied by either passing the
--binor--libflag to the command line, contains eitherbinorlib,--binis the default
- this is supplied by either passing the
os-arch- contains the current operating system and architecture ex:
linux-x86_64
- contains the current operating system and architecture ex:
username- this will be filled in by a function borrowed from Cargo's source code, that determines your information from Cargo's configuration.
within_cargo_project- A boolean with the value
trueif the template is being expanded inside aCargoproject. It's a simple matter of whetherCargo.tomlis present in any parent folder.
- A boolean with the value
is_init- A boolean that reflects the value of the
--initparameter ofcargo-generate.
- A boolean that reflects the value of the
Usage example
// README.md
This awesome crate `{{ crate_name }}` is brought to you by {{ authors }}.