Member-only story
Successful Object-Oriented Programming (OOP) in Rust: Mastering Five Critical Concepts From Python
Let’s closely look at the defining traits of Python’s object-oriented programming and assess how they match up with the Rust language. We will utilize Rust’s inherent strengths to identify solutions for OOP behaviors. So strap in and prepare for my journey into Rust and object-oriented programming!

In object-oriented programming, the definition of OOP remains a contentious topic, with numerous computer languages vying for acceptance.
Rust is not one of them.
I was dishearted when I read, from several prestigious sources, that Rust was not object-oriented.
Luckily, I found the object-oriented behaviors I used in Python; I could get almost all of them in Rust. The one I could not get, inheritance, I get close enough in Rust.
I will repeat it.
Strap in and prepare for my journey so far into Rust and object-oriented programming!
OOP in Python
Python is an object-oriented programming language, which means it supports a variety of object-oriented behaviors — five of which I detail for Python and then Rust.
Classes and objects: Python
Python allows you to define classes, which are user-defined types that can have attributes and methods. Objects are instances of classes that can hold specific values of their attributes.
Here is an example of an Object-Oriented Programming (OOP) “stubby” pattern for a 3D Vector in linear coordinates implemented in Python:
import math
class Vector3d:
"""A three-dimensional vector with Cartesian coordinates."""
def __init__(self, x, y, z):
"""Initializes the vector with the given coordinates."""
self.x = x
self.y = y
self.z = z
def __str__(self):
"""Returns a human-readable string representation of the vector."""
return "({}, {}, {})".format(self.x, self.y, self.z)
def…