Skip to content

docs: Explain why/when .lines() returns an error #37744

Closed
@anholt

Description

@anholt

context: I'm doing the newbie Rust thing of writing some program that reads lines of a file. From stackoverflow I find myself at BufReader.lines() and then BufRead.lines() docs.

What I'm finding confusing in the docs is that lines() returns a Result, but the example in the docs blindly unwrap()s that result, and so does every caller of lines() I find in demo code. It would be nice if BufRead (or, if it's more appropriate there, then maybe in BufReader's impl) would explain under what circumstances you'd get an error instead of Ok when reading a file, so I know if unwrap() is appropriate to use or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions