Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I use this in a few of my projects. Simple, no complaints. Compile time is faster than it takes for me to yawn most of the time (using mold linker and sccache, which improves compile time a lot with a far superior linker and caching compiled dependencies, respectively).

(Edit to add: below complaint is entirely within rust and irrelevant to this library)

Only problem (not the fault of egui) is sometimes the elements disallow me using the templateapp object mutably as a whole: sometimes I have to mut borrow a part of `self` before the ui part (instead of mutating `self.whatever` within the UI element, I have to do `let borrow = self.whatever.borrow_mut()` before the UI element then call that borrow) which seemed odd to me as a beginner. I think this is mostly a rust "problem" but also maybe because of how UI element creation was designed.

If you understand the borrow rules then you'll probably understand it fine. I might be able to just lock an Arc Mutex instead and avoid the problem but I just learned how to use them so :p



The awkwardness is because use of `self.whatever` in closures borrows `self` as a whole instead of just the `whatever` part. The good news is that Rust is going to fix this soon:

https://blog.rust-lang.org/2021/05/11/edition-2021.html#disj...


Oh thank god. This has been so annoying in the past


Thank you so much! that's very interesting.


If the problem is as pornel described, you can work around it by creating the borrow of self.whatever outside the closure.

Instead of:

    foo(|| {
        bar(&self.whatever);
    });
... do:

    let whatever = &self.whatever;
    foo(|| {
        bar(whatever);
    });
To avoid leaking `whatever` into the scope, there's an idiom that looks like this:

    foo({
        let whatever = &self.whatever;
        || {
            bar(whatever);
        }
    });


Yeah that's what I've had to do, it just seemed like an oversight tbh. Maybe the idea is to not keep the entire GUI state in a single object though, but it's the one time learning rust that I thought "hey that doesn't make sense". which really speaks to Rust's strengths, rather than its weaknesses. Can't wait for 2021




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: