← All notes

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

Sources

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

Permanent ID: iil:note:5djmt1py

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.},
}

Markdown

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.

All artifact files (JSON index)

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.