OOP in Rust: objects, encapsulation, and what the book says Rust supports
Answer: The Rust book says there is no consensus on what makes a language object oriented, then checks Rust against objects, encapsulation, and inheritance.
Objects as data plus behavior
Rust is influenced by many paradigms, including OOP and the functional features discussed in Chapter 13.
OOP languages are often said to share objects, encapsulation, and inheritance.
The Gang of Four book defines an object as a package of data and the procedures that operate on that data, usually called methods or operations.
Under that definition, Rust is object oriented: structs and enums hold data, and impl blocks provide methods on them.
Those types are not called objects, but they provide the same functionality.
Encapsulation
Encapsulation means a user of an object should not reach into its internals, and should go through a public API instead.
The only way to interact with an object is through its public API.
Rust controls this with the pub keyword; by default everything else is private.
AveragedCollection is marked pub for other code to use, while its fields remain private. add, remove, and average methods keep the cached average updated.
See also
Claims
- id: C1 claim: There is no single agreed list of features a language needs to be called object oriented. source: S1 evidence: "There is no consensus in the programming community about what features a"
- id: C2 claim: Under the Gang of Four definition, Rust is object oriented. source: S2 evidence: "Using this definition, Rust is object oriented"
- id: C3 claim: pub chooses what is public; everything else is private by default. source: S2 evidence: "We can use the
pubkeyword to decide which modules"
Sources
- [S1] Characteristics of Object-Oriented Languages. The Rust Project Developers. https://doc.rust-lang.org/book/ch18-01-what-is-oo.html . License: MIT OR Apache-2.0. Accessed 2026-11-27.
- [S2] Characteristics of Object-Oriented Languages (source). The Rust Project Developers. https://raw.githubusercontent.com/rust-lang/book/main/src/ch18-01-what-is-oo.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, Characteristics of Object-Oriented Languages; The Rust Project Developers, Characteristics of Object-Oriented Languages (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, Characteristics of Object-Oriented Languages; The Rust Project Developers, Characteristics of Object-Oriented Languages (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. "OOP in Rust: objects, encapsulation, and what the book says Rust supports." iinventedlight Library, iil:note:9zrr33pz, version of 2026-11-27. https://iinventedlight.com/library/notes/rust-oop-characteristics/. License: CC-BY-4.0.
@misc{iil_note_9zrr33pz,
author = {{iinventedlight}},
title = {{OOP in Rust: objects, encapsulation, and what the book says Rust supports}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-27},
url = {https://iinventedlight.com/library/notes/rust-oop-characteristics/},
note = {Permanent ID iil:note:9zrr33pz. 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-oop-characteristics.schema.json (schema; CC-BY-4.0)
- rust-oop-characteristics.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-oop-characteristics.md.