Sau Rust 1,0
read_line
bây giờ có một bộ đệm để phụ thêm vào, vì vậy giá trị trả về đã trở thành biểu cảm hơn. Từ documentation for read_line
:
If this reader is currently at EOF then this function will not modify buf
and will return Ok(n)
where n
is the number of bytes which were read.
Trước Rust 1,0
Tôi đã kiểm tra standard library version của BufferPrelude::lines
. Bạn sẽ muốn sử dụng một mô hình phù hợp chỉ định kind
lỗi:
match self.buffer.read_line() {
Ok(x) => Some(Ok(x)),
Err(IoError { kind: EndOfFile, ..}) => None,
Err(y) => Some(Err(y))
}
Là một sang một bên, bạn có thể sử dụng trực tiếp .lines()
:
for line in io::stdin().lock().lines() {
match line {
Ok(x) => ...,
Err(x) => ...,
}
}