Skip to content

BufRead::read_line is not as described in the io RFC #22588

@mahkoh

Description

@mahkoh
#![feature(io)]

use std::io::{BufRead};

fn main() {
    let buf = &[][];

    let mut reader = std::old_io::BufReader::new(buf);
    println!("{:?}", reader.read_line());

    let mut reader = std::io::BufReader::new(buf);
    let mut dummy = String::new();
    println!("{:?}", reader.read_line(&mut dummy));
}
Err(IoError { kind: EndOfFile, desc: "end of file", detail: None })
Ok(())

The read_until and read_line methods are changed to take explicit, mutable buffers, for similar reasons to read_to_end. (Note that buffer reuse is particularly common for read_line). These functions include the delimiters in the strings they produce, both for easy cross-platform compatibility (in the case of read_line) and for ease in copying data without loss (in particular, distinguishing whether the last line included a final delimiter).

In particular: No changes to the error semantics were mentioned in the RFC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions