1. 18
  1.  

  2. 5

    It’s common to see beginners spending lots of energy switching back and forth between their editor and a terminal to run rustc, and then scrolling around to find the next error that they want to fix.

    For a while I’ve been really skeptical of the I in IDEs, but I’ve had a great experience with the rust-enhanced Sublime plugin. Admittedly I’ve only worked in small codebases, but I’ve found it to be extremely fast. I’m not sure precisely how Sublime plugins work, but they don’t seem to cause the main render thread to block so you can still scroll without jank while cargo check runs in the background. Additionally, having inline compiler suggestions with one-click acceptance really helps while you’re learning (that’s a clickable button that automatically replaces your text with the suggestion).

    1. 2

      To make a type that can never be created, simply create an empty enum. Use this where you want to prevent compilation of specific codepaths.

      What does that mean, prevent compilation of specific code paths? When are we writing code paths that we don’t want to compile?

      1. 2

        For example, som API might be expecting a Result<V,E> type, but your specific operation can never fail. Then if you use the empty enum mentioned as the E-type, the compiler will know that there will never be an error and can remove all the error handling around your operation.

        There are plans to add a specific type to rust denoted !, called the never type, that has this specific meaning. Unfortunately the never type is problematic, so it has been delayed quite some time.

        1. 2

          On stable you can use ! for functions that never return, which is helpful in embedded where main should never return, or to make match arms typecheck when one of them exits the process, like a usage statement.

      2. 1

        I’ve been using shadowing to deal with Arc and thread::spawn. No indentation or incrementing required:

        let thing0 = Arc::new(thing);
        
        let thing = thing0.clone();
        thread::spawn(move || …);
        
        let thing = thing0.clone();
        thread::spawn(move || …);