Skip to content

Piero Bosio Social Web Site Personale Logo Fediverso

Social Forum federato con il resto del mondo. Non contano le istanze, contano le persone

An amusing but also actually useful thing in #RustLang: I realised this week that in some situations there's a good reason to write an apparent no-op let statement.let x = x;Because if x was previously mut, this makes it not mut any more

Uncategorized
2 2 11
  • An amusing but also actually useful thing in : I realised this week that in some situations there's a good reason to write an apparent no-op let statement.

    let x = x;

    Because if x was previously mut, this makes it not mut any more.

    In particular, this is a useful precaution for algorithms that use a data structure like a collection in two phases: (1) populate the data structure, (2) read stuff back out of it. If a stray mutation of the DS were to appear in phase 2 then perhaps it would invalidate all the stuff you'd already read out. Making the DS immutable at the end of phase 1 means the compiler will complain instead of letting the bug get as far as run time.

    Perhaps this is a well-known technique already? But I worked it out for myself, by thinking "it would be nice to be able to remove 'mut' from this variable here โ€ฆ hmm, I feel as if just 'let x=x' ought to have that effect โ€ฆ yes it does, aha!"

  • An amusing but also actually useful thing in : I realised this week that in some situations there's a good reason to write an apparent no-op let statement.

    let x = x;

    Because if x was previously mut, this makes it not mut any more.

    In particular, this is a useful precaution for algorithms that use a data structure like a collection in two phases: (1) populate the data structure, (2) read stuff back out of it. If a stray mutation of the DS were to appear in phase 2 then perhaps it would invalidate all the stuff you'd already read out. Making the DS immutable at the end of phase 1 means the compiler will complain instead of letting the bug get as far as run time.

    Perhaps this is a well-known technique already? But I worked it out for myself, by thinking "it would be nice to be able to remove 'mut' from this variable here โ€ฆ hmm, I feel as if just 'let x=x' ought to have that effect โ€ฆ yes it does, aha!"

    @simontatham It's a thing, though I usually prefer encasing the mutability part in a block:
    ```
    let x = {
    let mut x = ...;
    x += ...;
    x
    };
    ```

  • oblomov@sociale.networkundefined oblomov@sociale.network shared this topic on

Gli ultimi otto messaggi ricevuti dalla Federazione
Post suggeriti
  • 0 Votes
    1 Posts
    8 Views
    I distilled my four hour Rust training course for FOSS developer into a web page. I hope it's useful to people.This is the first full draft. It's probably going to need updates and fixes. Please reply to this message if you spot anything wrong. But feel free to boost and share if you want.https://liw.fi/distilled-rust/#Rust #RustLang
  • 0 Votes
    1 Posts
    8 Views
    Relax ๐Ÿ˜Ž! GPG is not OpenPGP!Yesterday, vulnerabilities were published https://gpg.fail but they don't affect #deltachat or other #chatmail clients becauseA) We never used #gnupg for anything; we use the modern #rustlang #openpgp implementation @rpgp, security audited multiple times.B) #openpgp is fine, as modernized in #RFC9580, which already warns against several #gpgfail issues (gpg didn't implement that spec)Please spread the word that #gpg is not #openpgp ... Thanks! #39c3
  • Hey everyone!

    Uncategorized fedihired rustlang linux
    1
    0 Votes
    1 Posts
    17 Views
    Hey everyone! I'm looking to get #FediHired as a (senior) #RustLang developer!If your team needs some additional people power, feel free to DM me and I'd love to have a talk or send my resume!I'm well versed in most areas, from low level system/ #Linux stuff, all the way to high abstraction full stack web stuff!โœจ Boosts appreciated! โœจ
  • 0 Votes
    1 Posts
    7 Views
    #GetFediHired I'm looking for a Rust job. ๐Ÿฆ€> I am a software developer with more than 10 years of experience, with a focus on backend web development.> I have more than 5 years of experience in the Rust programming language.--CV: https://raw.githubusercontent.com/teohhanhui/cv/refs/heads/main/cv.pdf(CV made with #typst: https://github.com/teohhanhui/cv/blob/main/cv.typ)--TYPE: Full time or contractLOCATION: I'm based in Malaysia.REMOTE: Yes, and open to relocation (not US).#rustjobs #rustlang