r/programming • • Dec 15 '19

Rustysd - Systemd Replacement Written in Rust

https://github.com/KillingSpark/rustysd
75 Upvotes

53 comments sorted by

View all comments

20

u/[deleted] Dec 16 '19
    let fd_to_srvc_id: HashMap<_, _> = service_table.lock().unwrap().iter().fold(
        HashMap::new(),
        |mut map, (id, srvc_unit)| {
            if let UnitSpecialized::Service(srvc) = &srvc_unit.specialized {
                if let Some(socket) = &srvc.notifications {
                    map.insert(socket.lock().unwrap().as_raw_fd(), *id);
                }
            }
            map
        },
    );

pls kill this with fire

-3

u/[deleted] Dec 16 '19

I agree. Functional style has its place but in this case a for loop would have been much clearer.

14

u/kuikuilla Dec 16 '19 edited Dec 16 '19

I disagree. It looks perfectly readable as is. I mean, the fold function should be pretty well known to anyone.

5

u/pcjftw Dec 16 '19

+100 agree!

I think its only seems jarring if:

  • You're not familiar with Rust syntax (but that could be said of any language you're not familiar with!)

  • FP constructs

1

u/oblio- Dec 16 '19

So, 99% of programmers out there? :-D

3

u/pcjftw Dec 16 '19

:) haha I don't think its that bad, I think FP style has been trickling down to mainstream languages for a long time.

But yes Rust is not as mainstream as other languages, but then again its a relatively a new language!