• 1 Post
  • 35 Comments
Joined 1 year ago
cake
Cake day: July 1st, 2023

help-circle

  • I can agree that the example function is not the best usecase. But the point still stand that there’s no realistic escape hatch from lifetimes and memory management in Rust.

    Cow does not work when you are actually required to return a reference, e.g. if you’re working with some other crate that requires that. Cow also has some more strict requirements on reborrows (i.e. you can reborrow a &'short &'long T to a &'long T, but you can only reborrow a &'short Cow<'long, T> to a &'short T).

    LazyLock can solve very specific issues like static, but is not a general escape hatch. Again, the example is not the best to showcase this, but imagine if you have to perform this operation for an unknown amount of runtime values. LazyLock will only work for the very first one.


  • (Note that I’m not the article author)

    In this example, you could have just made a constant with value 0 and returned a reference to that. It would also have a 'static lifetime and there would be no leaking.

    I believe the intention was to demonstrate something that works with runtime values too, and a constant 0 does not.

    Btw you can just write &0 to do what you proposed, there’s no need for an explicit constant/static.






  • Does GNOME really need an app to change the theme?

    You can also do what this app does manually. The point is that “themes” are an hack and not officially supported, as such it doesn’t make sense to provide an official interface to set them.

    KDE plasma has this natively…

    Do you mean for global themes, application styles or plasma styles? All application styles I can find either use Kvantum or require you to compile them manually…


  • Software implementations of those features is often slower, and runtime checking can often be too expensive compared to the gains.

    since it seems like nobody but cachy or custom kernel runs anything but V1

    Gentoo offers x86_64-v4 binary builds too.

    There was a proposal for Fedora too, though it was ultimately rejected.


    Ultimately the gains right now seem to be only 1-3%, though that might also be because there’s not much demand for these kind of optimizations. If more distros enable them they might become more widespread and the benefits might increase too. It’s a chicken-egg problem though.





  • It’s mentioned in footnote 6:

    As an example, to make this work I’m assuming some kind of “true deref” trait that indicates that Deref yields a reference that remains valid even as the value being deref’d moves from place to place. We need a trait much like this for other reasons too.

    It would only work for references that are stable after the value they reference is moved. Think for example of a &str you get from a String.




  • GNOME devs never said that theming is incompatible (just “not supported”), and you’re still not explaining whay you mean with “incompatible” either. Managing window controls also doesn’t seem a requirement to be “compatible”, as the app still runs fine even with client side decorations (again, it just won’t fit visually with the rest of the system).

    And by the way, the problem is not theming per-se, but the fact that apps get themed by default, they inevitably break by default, and app developers are left to deal with that. Nobody ever tried to improve the situation so the solution they came up with is to have their apps always look the same.




  • They tested the same strings on that implementation

    The code they were looking at was used for writing the table, but they were testing the one that read it (which is instead correct).

    though judging by the recent comments someone’s found something.

    Yeah that’s me :)The translation using an associated const also works when the const block uses generic parameters. For example:

    fn require_zst() {
        const { assert!(std::mem::size_of::() == 0) }
    }
    

    This can be written as:

    fn require_zst() {
        struct Foo(PhantomData);
        impl Foo {
            const FOO: () = assert!(std::mem::size_of::() == 0);
        }
        Foo::::FOO
    }
    

    However it cannot be written as:

    fn require_zst() {
        const FOO: () = assert!(std::mem::size_of::() == 0);
        FOO
    }
    

    Because const FOO: () is an item, thus it is only lexically scoped (i.e. visible) inside require_zst, but does not inherit its generics (thus it cannot use T).