Skip to content

Document additional use case for Iterator::inspect #49564

Closed
@nickbabcock

Description

@nickbabcock

If you'd like to fix this bug, here's how.


Currently iterator::inspect contains the following documentation:

It's much more common for inspect() to be used as a debugging tool than to exist in your final code, but never say never.

Though I like the never say never wording, I think it might be helpful to document a use case where it's not used for debugging. I use inspect in daemon applications for that slurp in stdin lines and discard and log the lines that can't be parsed. Like so:

lines
.iter()
.map(|line| parse_line(line))
.inspect(|line| {
    // If we can't parse a line, yeah that sucks but it's bound to happen so discard
    // the line after it's logged for the attentive sysadmin
    if let Err(ref e) = *line {
        error!("Parsing error: {}", e);
    }
})
.flat_map(|x| x)
// etc

Maybe the documentation of inspect can be updated to something like:

It's more common for inspect() to be used as a debugging tool than to exist in your final code, but applications may find it useful in certain situations as well. Say an application is reading stdin lines, it may be it helpful to log lines with errors before discarding them.

What do you think? Suggestions certainly wanted 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-iteratorsArea: IteratorsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions