this post was submitted on 02 Jun 2024
47 points (100.0% liked)

Rust

6139 readers
12 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
47
The borrow checker within (smallcultfollowing.com)
submitted 6 months ago by turbohz to c/rust
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 6 points 6 months ago

The more I thought about the interior references part the more questions I had! For example:

  • The actual characters in a String belong to a dynamic memory allocation rather than to the String object itself, so the lifetime of &str references into there is "until any operation that might change the size of the allocation". Since that level of detail doesn't seem visible to to the type system even with the discussed addition, I guess it would reduce just to disallowing any mutable reference to the string so that its content cannot possibly move to a new allocation while the internal references are live. ๐Ÿค”
  • I also thought about the idea that a reference whose lifetime is related to another field in the same object could be represented as an offset from the object's address rather than an absolute pointer and then generate relative accesses when dereferencing, but that would mean that the referents would need to always live inside the object itself, and not in a dynamic allocation as would be the case for &str into a String.

So, with all of that said, I'd love to read an article with more details on that part!