Hacker News new | ask | show | jobs
by Marco012 19 days ago
A long time ago I came across a massive issue in my Rust project due to the borrow checker (typical Rust beginner). The thing is, that code wasn't unsafe at all, it just wasn't compatible with Rust's way of doing things.

I'm the type of person that uses getters and setters for everything, I don't really like public fields so I naturally do that in Rust too. But of course it doesn't work well, Rust doesn't know that a pos_mut() and rot_mut() return inner fields, so it simply doesn't allow you to call both functions together.

Thinking about this for a long time, I came to the conclusion: Why doesn't the function mention which field the returned reference is from? If the function says that pos_mut() is "attached" to the pos field, and rot_mut() is "attached" to the rot field, then the compiler would be able to distinguish both references by the function call.

That initial idea became what I now call the "Ties" concept in the Dazzle programming language, which I've been designing. It's on a very early stage but so far it's proving my point. I would love to hear some feedback, especially some situations where this approach may fall short. Thanks