← All notes

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

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

Permanent ID: iil:note:9zrr33pz

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

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-oop-characteristics.md.