correct. unsafe { } means within this block of code I have upheld the invariant. whereas marking the fn unsafe means, you the callee need to uphold some invariant.
-
-
Replying to @mgattozzi @sgrif
does "invariant" here only include invariants the borrow checker can prove, or any invariant at all? would one ever mark a fn unsafe if it didn't contain anything that would require an unsafe block (i.e. raw ptr deref etc)
3 replies 0 retweets 1 like -
like, I could write a broken impl of some data structure in safe rust, but marking its API unsafe wouldn't fix that
1 reply 0 retweets 0 likes -
Replying to @mountain_ghosts @mgattozzi
Right, `unsafe` is very specifically about memory safety and undefined behavior
1 reply 0 retweets 1 like -
Replying to @sgrif @mountain_ghosts
though I do wish there was some way that wasn't `unsafe` to say hey like if you use the API this way you might have a bad time if you don't do x, y, and z
1 reply 0 retweets 0 likes -
Replying to @mgattozzi @sgrif
I would simply not write APIs with this property being slightly facetious but to me a core element of object APIs is that it should not be possible to put them in a bad state by any sequence of messages
1 reply 0 retweets 2 likes -
Replying to @mountain_ghosts @sgrif
I had some weird stuff porting your git book over to rust and file locking where there were some issues around ownership or whatever. Can't remember the exact reason. While I had to make an escape hatch in the API to get it to work I wasn't happy about it. Not sure what the cause
1 reply 0 retweets 0 likes -
Would really be. Whether it was my as close to 1:1 mapping or if my API painted me into a weird corner
1 reply 0 retweets 0 likes -
Replying to @mgattozzi @sgrif
yeah learning rust has involved unlearning a bunch of ways I often do OOP b/c they won't pass borrowck (a lot of OOP is creating networks of mutable references so they don't translate at all)
2 replies 1 retweet 4 likes -
but message-passing OOP works great -- transferring values between objects that are the sole owners of their mutable state it's just a fair bunch of common OOP patterns involve things you'd need a RefCell for in rust
1 reply 0 retweets 2 likes
You shouldn't feel bad about using RefCell when appropriate FWIW
-
-
Replying to @sgrif @mgattozzi
sure sure but it makes you notice how a language like ruby treats *all* references to data like a RefCell and RefCell will still reject things I'd do in ruby at runtime
1 reply 0 retweets 2 likes -
Replying to @mountain_ghosts @sgrif
I don't often need it but when I do it's great.
0 replies 0 retweets 0 likes
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.