Skip to content
Discussion options

You must be logged in to vote

Your assertions that you don't need mut to edit the value behind a Box are false:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=48e8e1d406dcb157dc29800d28058d0a

Basically, it's like this because it's impossible for us to not require this; at least without reverting to runtime borrow checking (in the style of RefCell), which would be stupid. Ideally we'd be able to tell rustc that our types are 'inherently mutable' like &mut T, but there's no mechanism to do this in the language.

(Your comment about Rc is weird, since Rc only gives immutable access to the target value, unless you use make_mut, but that also requires the Rc is mut)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ghost
Comment options

@DJMcNab
Comment options

DJMcNab Sep 28, 2021
Collaborator

@ghost
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant