Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use let-if chain in "Log in with github" bit when rustfmt supports them #130

Closed
Dygear opened this issue Nov 24, 2022 · 2 comments
Closed
Labels
blocked enhancement New feature or request

Comments

@Dygear
Copy link

Dygear commented Nov 24, 2022

It's no so much "wrong" as it could be updated I think -- This moves away from ...

https://fasterthanli.me/series/updating-fasterthanli-me-for-2022/part-6#position=59.3

Here's what it is:

        for item in patreon_response.data {
            if let Item::Member(member) = item {
                if let Some(full_name) = member.attributes.full_name.as_deref() {
                    if let Some(entitled) = member.rel("currently_entitled_tiers") {
                        for item_ref in entitled.data.iter() {
                            let ItemRef::Tier(tier_id) = item_ref;
                            if let Some(tier) = tiers_per_id.get(&tier_id.id) {
                                if let Some(title) = tier.attributes.title.as_deref() {
                                    if credited_tiers.contains(title) {
                                        credited_patrons.insert(full_name.to_string());
                                    } else {
                                        trace!("Tier {title} not credited");
                                    }
                                }
                            } else {
                                trace!("Tier for id {} not found", tier_id.id);
                            }
                        }
                    } else {
                        trace!("No currently_entitled_tiers for member: {}", full_name);
                    }
                }
            }
        }

With 1.65.0's if let this no longer needs to be a tower?

for item in patreon_response.data {
    if let Item::Member(member) = item else {
        continue;
    }

    if let Some(full_name) = member.attributes.full_name.as_deref() else {
        continue;
    }

    if let Some(entitled) = member.rel("currently_entitled_tiers") else {
        trace!("No currently_entitled_tiers for member: {}", full_name);
    }

    for item_ref in entitled.data.iter() {
        let ItemRef::Tier(tier_id) = item_ref;

        if let Some(tier) = tiers_per_id.get(&tier_id.id) else {
            trace!("Tier for id {} not found", tier_id.id);
        }

        if let Some(title) = tier.attributes.title.as_deref() else {
            continue;
        }

        if credited_tiers.contains(title) {
            credited_patrons.insert(full_name.to_string());
        } else {
            trace!("Tier {title} not credited");
        }
    }
}

Not sure if that's actually better or just different and I'm like "Oh I know a thing. Maybe I should use the thing."

@fasterthanlime
Copy link
Owner

No I agree, this would be a fantastic place for it. I think I'll wait until rustfmt is able to format let else properly until I do that though!

@fasterthanlime fasterthanlime changed the title Implementing "Log in with GitHub" Use let-if chain in "Log in with github" bit when rustfmt supports them Mar 11, 2023
@fasterthanlime fasterthanlime added blocked enhancement New feature or request labels Mar 11, 2023
@fasterthanlime
Copy link
Owner

I regret to inform you that:

image

(lol @ result 2 being me complaining about it)

Also rust-lang/rustfmt#4914 is still open

I'm gonna go ahead and free myself from this issue tbqh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants