home.social

#borrowchk — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #borrowchk, aggregated by home.social.

  1. @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:
    play.rust-lang.org/?version=st

    On Borrrow Splitting:
    doc.rust-lang.org/nomicon/borr

    On scoped threads API:
    doc.rust-lang.org/std/thread/f

    #Rust #RustLang #BorrowChk #Concurrency #Threads

  2. A comparison of #Rust’s borrow checker to the one in C# - by em-tg (emy)

    em-tg.github.io/csborrow/

    Found here:
    users.rust-lang.org/t/a-compar

    Oh, you didn't know #CSharp had a borrow checker? Me neither!😁

    _Finally_ a language comparison that makes sense!

    #RustLang #BorrowChk

  3. @zethtren @synlogic @echo

    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.

    #RustLang #BorrowChk

  4. "Can't move a closure into a spawned thread"

    users.rust-lang.org/t/cant-mov

    or phrased differently: "Misunderstandings of what the 'static lifetime in #Rust means".

    Kornel's excellent answer:
    users.rust-lang.org/t/cant-mov

    "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."

    #RustLang #BorrowChk

  5. Practical suggestions for building #intuition around borrow errors - by quinedot

    quinedot.github.io/rust-learni

    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_...

    floss.social/@janriemer/109415

    ...so this learning resource takes the same line (according to its title)! Nice!

    #RustLang #BorrowChk

  6. @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:

    #Rust #BorrowChk

  7. @wtfrank You can use a concept called "Split Borrows" or "Borrow Splitting":

    doc.rust-lang.org/nomicon/borr

    Here is a playground that shows it:
    play.rust-lang.org/?version=st

    It 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:
    doc.rust-lang.org/std/primitiv

    #Rust #RustLang #SplitBorrows #BorrowChk