this post was submitted on 29 Apr 2026
34 points (100.0% liked)

Rust

8026 readers
65 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
top 4 comments
sorted by: hot top controversial new old
[–] MoSal@programming.dev 10 points 2 weeks ago (1 children)

I didn't realize this was posted here.

Allow me to copy my comment from another thread:


// Don't bail on the first error, but remember the worst one.
let mut worst = 0;
for file in files {
    if let Err(e) = chmod_one(file) {
        worst = worst.max(e.exit_code());
    }
}
process::exit(worst);

This is not rustic, I feel.

files.iter()
  .map(chmod_one)
  .filter_map(Result::err)

is more like it.

From there, you can next() for first error, last() for last error, or fold() for max error, or collect() if you need to save all errors.


And no, static compilation doesn’t help here, because get_user_by_name goes through NSS, which dlopens libnss_* modules at runtime regardless of whether your binary is statically linked.

This is not true in musl systems. I just quickly checked in a Chimera rootfs (which has a system dynamic musl libc btw).

I believe the described dlopening is one of the well known reasons why GNU libc is not suitable for static linking, unlike musl!

In Arch, this indeed loads /usr/lib/libnss_systemd.so.2.

Everyone can test this with strace id 2>&1 | egrep 'open.*\.so'.

[–] blazebra@programming.dev 0 points 2 weeks ago (1 children)

In that for, all error messages have been lost. If to add such output “for” is the most elegant solution.

[–] Skipcast@lemmy.world 1 points 2 weeks ago (1 children)

No they're in the resulting iterator

[–] blazebra@programming.dev 1 points 4 days ago

The usual handling in Rust afterwards is in most cases log one error or return to upstream “there was an error”. In some rare cases all errors returned as a single case.

Both of these first are bad for i18n and finding what’s really happened in the middle.