-
Notifications
You must be signed in to change notification settings - Fork 165
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
improve unix/ls task #698
improve unix/ls task #698
Conversation
Rust 2018 lets you use this when defining the main return signature accordingly.
tasks/unix/ls/src/main.rs
Outdated
fn print_files(path: &Path) -> std::io::Result<()> { | ||
// flatten entries to avoid calling .unwrap() | ||
let mut entries: Vec<_> = fs::read_dir(path)? | ||
.flat_map(|res| res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: I still am learning flat_map
and iterator chains. Something feels odd about needing to call both of them. I had tried map_or
but couldn't call that directly on the ReadDir
iterator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can combine them:
.flat_map(|entry| {
entry.ok().map(|entry| entry.file_name())
})
bors r+ |
?
operator overunwrap()