It’s nice to see how this blog post not only lists features, but also lists what the limitations of the approach are, and how to turn it off if it’s not suitable for your program. No magic bullet, after all, but good enough for most use cases.
- 1 Post
- 5 Comments
notriddle@programming.devto
Rust@programming.dev•Could rust do with a crates.io alternative?
4·3 years agoWhy should I believe this?
I followed the link in echelon’s HN profile to their GitHub profile. It’s the same name, like you’d expect, but I had to check.
If they were a member of the Rust project, they’d have an entry in the rust-lang/team repository, and they don’t. The fact that they’ve written some code in the Rust language doesn’t automatically make them trustworthy, or give them information about what happens in closed council meetings.
notriddle@programming.devto
Rust@programming.dev•Semver violations are common, better tooling is the answer
1·3 years agoThat’s a good point.
cargo-semver-check should definitely provide a way to mark syntactically-public items as “de-facto private,” because some projects just need to do bad things and leaving them out in the cold is not helpful. But you’ve convinced me that
doc(hidden)is a poor way to do it.
notriddle@programming.devto
Rust@programming.dev•Semver violations are common, better tooling is the answer
5·3 years agoWhat do you think
#[doc(hidden)]is for, other than declaring something “private” that the language unfortunately doesn’t let you declare as truly private right now?I’ve mostly seen it used as a way to expose tools to macro APIs. For example, these internal parts of the
quote!macro, or these internal parts of thevec!macro. Changing these things shouldn’t be considered a semver violation, because they’re not really part of the API, even though thequote!macro can’t enforce it.The only other cases I can think of where I’ve seen
#[doc(hidden)]used are even bigger kludges, and the hidden items definitely aren’t part of the platonic API, like pre-#[non_exhaustive]crates that wanted to reserve the right to add new variants to their enums.

As much as I understand why Rustaceans don’t like classical inheritance, that’s only a minor factor in Rust not having support for it.
Before 1.0, there was a project to solve Servo’s needs for inheritance. An important point about this is how it made the question of whether inheritance is good or not moot — Servo implements the DOM, and the DOM needs inheritance, end of story.
Servo uses a bunch of procedural macros to implement OOP, and so do other projects in similar positions (GNOME, PyO3, Windows…). Anything worth adding to Rust needs to be better than that.
Solving inheritance for Servo means it needs to be as fast as C++ (the Internals thread linked above is mostly about this requirement). It’s hard, because C++ doesn’t prevent things like object slicing, and a safe implementation of subclassing for Rust would need to (while still providing control over an object’s allocation like C++ does).
About object slicing: TFA describes inheritance as having a “hidden member variable” within a child class that’s an instance of the parent class. This is mostly how it works, but it’s important in trad OOP that the child class encapsulates the parent completely. For example, if you’re implementing the DOM and an
HTMLTemplateElementwants to implement its own clone and adopt steps, there should not be any way to bypass them. Also, it should not be possible to get a reference&mut Nodeand usemem::replacewith a non-template, since that would still be a way to violate the invariants those methods seek to enforce.JS, Python, and WinRT are all substantially different. Covering all of them means the language features look less like a complete object system and more like a framework for building an object system.
Note: it’s been a long time since I last made any meaningful contributions to Servo, and I never worked on the JS bridge code much. I’m reflecting the story as best I can. Please read the original Internals thread to get a deeper understanding of this, without creating a bad game of telephone.