• 3 Posts
  • 15 Comments
Joined 1 year ago
cake
Cake day: August 5th, 2023

help-circle


  • A closure may/will try to capture by reference, so it may hold references to the calling function’s scope. For example, this would want to hold a reference to x:

    let x = 0;
    std::thread::spawn(|| x += 1);
    

    It’s as if you had a struct like this:

    struct MyClosure<'a> {
        x: &'a mut i32,
    }
    

    That makes the closure non-'static, since it holds non-'static references. The usual solution is to use the move keyword, to hint that you want it to move by default, or to use scoped threads. But yeah Send and 'static depend on the captures.

    Am I correct in guessing that you handle is of Gontian origin?

    Yes! 😁 I picked it when I used to play Tibia (15-20 years ago!), and it stuck with me since then. The correct spelling was already taken, so I modified it a bit. This name is usually available.


  • Your guess is correct, it should be understood as

    F: ( FnOnce() -> T ) + Send + 'static
    T: Send + 'static
    

    The FnOnce() -> T is syntax sugar for FnOnce<(), Output = T> and the bounds after apply to F. That’s also why T has separate bounds. They aren’t propagated or inherited. It’s just an ambiguous looking syntax, but T + Trait + 'lifetime isn’t a valid syntax for applying bounds to T (unless I missed something).

    The type F may be a closure over values from the calling thread. It has to be possible to send these values to the spawned thread, hence F needs Send + 'static. When the thread is done with its work, it returns a value of type T that gets passed back via JoinHandle<T>, so T needs Send + 'static too.

    I hope this cleared things up a bit.







  • This depends a bit on what you are looking for. The library documentation is supposed to guide you to a practical starting point, but it’s still quite light on the theoretical parts. I haven’t really collected any specific beginner material, so this may still be a bit technical. There’s a ton of info about the basics, with varying levels of detail.

    Assuming you are starting from almost nothing, I would recommend getting familiar with what RGB is and how its components relate. This is the format most images are encoded in and most devices and software use. The Wikipedia page is quite thorough, so no need to read all of it: https://en.wikipedia.org/wiki/RGB_color_model

    Next, it’s good to know there are other models. HSV and HSL tend to be used in color pickers (a bit more intuitive than RGB), so you have probably interacted with them at some point. Again, the Wikipedia page may be a good source: https://en.wikipedia.org/wiki/HSL_and_HSV

    That’s often good enough for producing colors and reading or writing images. If you want to go more into editing, it’s good to know that you will need to massage the values you get from the images. They usually don’t represent the actual light intensities, so they have to be made linear. Palette offers functions for it and represents it in the type system. This video is a slightly simplified explanation of the problem (when it mentions the square root, it’s an approximation): https://youtu.be/LKnqECcg6Gw

    At some point, you will realize that neither linear nor non-linear RGB is the universal answer to good looking colors. They are used in different situations. There is another category of color models/spaces that are called “perceptually uniform”, meaning that they try to simulate or predict how we actually experience the colors and relate it to the numbers in the computer. This page shows the problem and introduces one of those models: https://bottosson.github.io/posts/colorwrong

    I can probably provide more sources if you have any specific things you want to read about, but this is a start.




  • I would say it’s very useful when you are looking for one specific pattern, which happens a lot with Option<T>. Plus, being able to chain it in if / else if / else chains helps with organizing the code. It generally doesn’t grow as deep as with match.

    That said, match is fantastic and it’s totally fine to prefer using it. if let and let else are there for those cases when you tend to discard or not need to use the other values than the matched one. How often that happens depends on what you are doing.




  • ICC profiles are definitely part of the field, but that’s sort of a topic of its own. At least in terms of scope. The color space rabbit hole is so deep that I never got as far as including them. There are other crates that go into those parts and it should be easy to bridge between them and Palette.

    I would say Palette is more for the “business logic” of working with colors, so converting, manipulating and analyzing. The difference from ICC profiles when converting with Palette is that you need to know more about the source and destination color spaces during compile time. ICC profiles use more runtime information.

    Palette could be used for applications like image manipulation programs, 3D rendering, generative art, UI color theme generation, computer vision, and a lot more. A lot of people also use it for smaller tasks like converting HSL input to RGB output or making gradients.



  • I’m of course only one single anecdotal sample, but the release cadence has probably been the least of my problems. My experience is that it’s fine to not update for quite some time. I have a crate with 1.60 (released about one and a half years ago) as MSRV, which means I run unit tests with that version, as well as stable, beta and nightly. The only pressure to upgrade is that some dependencies are starting to move on. Not that the newer compilers reject my code, not even anything deprecated.

    Also, small, frequent releases usually takes away a lot of the drama around upgrading, in my experience. Not the opposite. A handful of changes are easier to deal with than a whole boatload. Both for the one releasing and for the users.