Rust functions: the fn keyword, snake case, and typed parameters
Answer: Functions are prevalent in Rust code. The fn keyword allows you to declare new functions, and snake case is the conventional style for function and variable names.
Defining and calling functions
The main function is the entry point of many programs, and fn is the keyword that declares a new function.
Snake case, with all lowercase letters and underscores between words, is the conventional style for function and variable names.
A definition is fn, a name, parentheses, and curly brackets around the body.
You call a function by writing its name and parentheses.
Rust does not care whether a function is defined before or after its caller, only that it is defined in a scope the caller can see.
Lines in main run in the order they appear.
Parameters
Parameters are special variables that are part of a function's signature.
The concrete values you pass are technically called arguments, though casual talk often uses parameter and argument interchangeably.
Each parameter's type must be declared in the signature, for example x as i32.
That design choice means the compiler almost never needs type annotations elsewhere to know what you mean, and it can give more helpful errors.
When a function has more than one parameter, separate the declarations with commas.
See also
Claims
- id: C1 claim: Functions are prevalent in Rust code. source: S1 evidence: "Functions are prevalent in Rust code"
- id: C2 claim: Function and variable names conventionally use snake case. source: S2 evidence: "Rust code uses _snake case_ as the conventional style"
- id: C3 claim: Each parameter in a function signature must have a declared type. source: S2 evidence: "you _must_ declare the type of each parameter"
Sources
- [S1] Functions. The Rust Project Developers. https://doc.rust-lang.org/book/ch03-03-how-functions-work.html . License: MIT OR Apache-2.0. Accessed 2026-11-27.
- [S2] Functions (source). The Rust Project Developers. https://raw.githubusercontent.com/rust-lang/book/main/src/ch03-03-how-functions-work.md . License: MIT OR Apache-2.0. Accessed 2026-11-27.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Functions; The Rust Project Developers, Functions (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Functions; The Rust Project Developers, Functions (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "Rust functions: the fn keyword, snake case, and typed parameters." iinventedlight Library, iil:note:5djmt1py, version of 2026-11-27. https://iinventedlight.com/library/notes/rust-functions/. License: CC-BY-4.0.
@misc{iil_note_5djmt1py,
author = {{iinventedlight}},
title = {{Rust functions: the fn keyword, snake case, and typed parameters}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-27},
url = {https://iinventedlight.com/library/notes/rust-functions/},
note = {Permanent ID iil:note:5djmt1py. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-functions.schema.json (schema; CC-BY-4.0)
- rust-functions.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-functions.md.