Skip to content

Promote or_default idiom for checking file names - #151

Open
matklad wants to merge 1 commit into
BurntSushi:masterfrom
matklad:or-default-idiom
Open

Promote or_default idiom for checking file names#151
matklad wants to merge 1 commit into
BurntSushi:masterfrom
matklad:or-default-idiom

Conversation

@matklad

@matklad matklad commented Jul 3, 2021

Copy link
Copy Markdown

Not sure how you'd feel about it, but decided to PR just in case!

unwrap_or_default() feels somewhat easier to read than .map and
.unwrap_or_false. It doesn't make a big difference here, but we can
use an opportunity to teach folks that this idiom exists.

Note that both version work incorrectly for non-utf8 file names, which
is unfortunate, but isn't something we can do anything about in the
example.

`unwrap_or_default()` feels somewhat easier to read than `.map` and
`.unwrap_or_false`. It doesn't make a big difference here, but we can
use an opportunity to teach folks that this idiom exists.

Note that both version work incorrectly for non-utf8 file names, which
is unfortunate, but isn't something we can do anything about in the
example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant