Nomenclature - struct vs object

What does one call a "struct with methods" in Rust?

I've been calling them "objects", but each time I do I cringe a little. Now I'm actually writing some documentation that other people will read and I want to use proper, idiomatic, terminology.

I personally don't see an issue with calling them objects. They encapsulate both state and operations in one "thing". Whether or not you call that thing an "object" seems largely a matter of taste.

But if it's causing an issue maybe try to tackle this from the other direction. A struct can have data and methods so what do you call a struct without methods? Wikipedia tells me it's called a Passive data structure although POD (Plain Old Data) is more familiar to me.

1 Like

This section from the book is a nice reference:

It mostly uses terminology like, “the instance of a struct”, though sometimes it uses “struct” to mean the instance of the struct too. In one code snippet it uses object, but I think that’s mostly to match the C++ example.

I wouldn’t normally make much distinction between a struct type and a struct instance (I’d just say struct), I think it is usually clear from context. Using “instance” might be a good idea though, since eg enums can have methods too, and if the method call is on a generic it might not be a struct anyway.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.