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
- id: C1 claim: Methods belong to the type named by the impl block. source: S1 evidence: "Everything within this impl block will be associated with the Rectangle type."
- id: C2 claim: &self is shorthand for a Self receiver borrowed immutably. source: S2 evidence: "The
&selfis actually short forself: &Self."
- id: C3 claim: Parentheses distinguish a same-named method from the field. source: S1 evidence: "When we don't use parentheses, Rust knows we mean the field width ."
Sources
- [S1] Methods - The Rust Programming Language. The Rust Project Developers. https://doc.rust-lang.org/book/ch05-03-method-syntax.html . License: MIT OR Apache-2.0. Accessed 2026-11-26.
- [S2] Methods (source). The Rust Project Developers. https://raw.githubusercontent.com/rust-lang/book/main/src/ch05-03-method-syntax.md . License: MIT OR Apache-2.0. Accessed 2026-11-26.
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
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.},
}
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-method-syntax.schema.json (schema; CC-BY-4.0)
- rust-method-syntax.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-method-syntax.md.