std::io::* 2. Struct std::io::BufReader

DongSub_Joung·2022년 1월 6일
0

std::io

목록 보기
4/4
post-thumbnail

https://doc.rust-lang.org/std/io/struct.BufReader.html

요약

small and repeated read calls to the same file or network socket.

  • when reading very large amounts at once, or reading just one or a few times. >> 별로 도움이 안된다.
  • 멀티 스레딩에서 데이터 손실 위험성( BufReader::into_inner도)
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
fn main() -> std::io::Result<()>{
    let f= File::open("log.txt")?;
    let mut reader= BufReader::new(f);

    let mut line= String::new();
    let len= reader.read_line(&mut line)?;

    println!("First line is {} bytes long", len);
    Ok(())
}

Implementations

impl<R: Read> BufReader

pub fn new(inner: R) -> BufReader

pub fn with_capacity(capacity: usize, inner: R) -> BufReader

impl BufReader

pub fn get_ref(&self) -> &R

pub fn get_mut(&mut self) -> &mut R

pub fn buffer(&self) -> &[u8]

pub fn capacity(&self) -> usize

pub fn into_inner(self) -> R

impl<R: Seek> BufReader

pub fn seek_relative(&mut self, offset: i64) -> Result<()>

0개의 댓글