#borrowchk — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #borrowchk, aggregated by home.social.
-
@kloetzl You can use a concept called "Borrow Splitting" in combination with scoped threads.
This way, your slices that your threads operate on, can have a lifetime shorter than 'static and you don't need to use #unsafe shenanigans. :ferris:
Please see this playground with comments on how to do this:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6b028d5bab84d739d34d76d66a750578On Borrrow Splitting:
https://doc.rust-lang.org/nomicon/borrow-splitting.htmlOn scoped threads API:
https://doc.rust-lang.org/std/thread/fn.scope.html -
A comparison of #Rust’s borrow checker to the one in C# - by em-tg (emy)
https://em-tg.github.io/csborrow/
Found here:
https://users.rust-lang.org/t/a-comparison-of-rusts-borrow-checker-to-the-one-in-c/120324Oh, you didn't know #CSharp had a borrow checker? Me neither!😁
_Finally_ a language comparison that makes sense!
-
I think there is a big misconception that Rust's Ownership/Borrowing semantics was only about memory (safety).
It is _much_ more than that.
Even if for some reason #Rust had garbage collection, I would still want borrowing semantics.
-
"Can't move a closure into a spawned thread"
https://users.rust-lang.org/t/cant-move-a-closure-into-a-spawned-thread/111332
or phrased differently: "Misunderstandings of what the 'static lifetime in #Rust means".
Kornel's excellent answer:
https://users.rust-lang.org/t/cant-move-a-closure-into-a-spawned-thread/111332/8?u=janriemer"Note that any lifetime bounds, including 'static, apply only to references and types containing references. They do nothing when applied to self-contained types. This means that String is not 'static, but rather it isn't affected by any lifetime bound."
-
Practical suggestions for building #intuition around borrow errors - by quinedot
https://quinedot.github.io/rust-learning/lifetime-intuition.html
If you're struggling with the #Rust borrow checker and lifetimes, this is an excellent resource!
In some past toot I've said that Rust lends itself very well to _intuition-based learning_...
https://floss.social/@janriemer/109415274612140073
...so this learning resource takes the same line (according to its title)! Nice!
-
@ferrous This is one of the best explanations about solving certain borrow checker issues I have ever read!
The part where you explain that &-refs are Copy, but &mut-refs are not, but instead a reborrow happens is mind-blowing! 🤯
Thank you for this excellent blog post!❤️ Every Rustacean should read this!
Very excited for part 2 of the series. :awesome:
-
Obscure Rust: reborrowing is a half-baked feature - by Thoughts with wings (2022-06)
-
@wtfrank You can use a concept called "Split Borrows" or "Borrow Splitting":
https://doc.rust-lang.org/nomicon/borrow-splitting.html
Here is a playground that shows it:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=607b3986ab9c04a3b918e55c5a2d2163It boils down to the following:
You can split your vector (or rather slice) into two mutable parts and mutate each half individually, by using `split_at_mut` on slices:See docs in std:
https://doc.rust-lang.org/std/primitive.slice.html#method.split_at_mut