← All notes

Rust method syntax: define methods in impl blocks with a self receiver

Answer: Rust methods are functions defined in an impl block for a type such as a struct, and you call them with dot syntax on an instance.

impl blocks and the self receiver

Methods look like functions: you declare them with fn, they have a name, they can take parameters and return a value, and their body runs when the method is called.

Unlike free functions, they are defined in the context of a struct, or of an enum or trait object.

Everything inside the impl block is associated with that type, such as Rectangle.

You call a method on an instance with a dot, the method name, and parentheses.

In the signature, &self stands in for rectangle: &Rectangle, and &self is short for self: &Self.

Inside an impl block, Self aliases the implemented type. The first parameter must be named self and have type Self, so Rust lets you write just self. A method may own self or borrow it, using &mut self to change the instance.

Getters and automatic dereferencing

A method may share a name with a struct field: parentheses call the method, and their absence reads the field.

Same-named methods that only return the field are often called getters, and Rust does not generate them automatically.

Rust has no -> operator; it relies on automatic referencing and dereferencing, and method calls are one of few such places.

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, Methods - The Rust Programming Language; The Rust Project Developers, Methods (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, Methods - The Rust Programming Language; The Rust Project Developers, Methods (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:5bgnrsgq

iinventedlight. 2026. "Rust method syntax: define methods in impl blocks with a self receiver." iinventedlight Library, iil:note:5bgnrsgq, version of 2026-11-26. https://iinventedlight.com/library/notes/rust-method-syntax/. License: CC-BY-4.0.

@misc{iil_note_5bgnrsgq,
  author = {{iinventedlight}},
  title = {{Rust method syntax: define methods in impl blocks with a self receiver}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/rust-method-syntax/},
  note = {Permanent ID iil:note:5bgnrsgq. 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-method-syntax.md.