TextReader

Struct TextReader 

Source
pub struct TextReader<R: Read> { /* private fields */ }
Expand description

The TextReader struct is wrapper for BufReader to decode text codecs.

Implementations§

Source§

impl<R: Read> TextReader<R>

Source

pub fn new( bufreader: R, encoding: &dyn Encoding, trap: DecoderTrap, ) -> TextReader<R>

Creates a new TextReader with codec.

§Examples
extern crate textstream;
extern crate encoding;
use std::fs::File;
use encoding::label::encoding_from_whatwg_label;
use encoding::{DecoderTrap, Encoding};
use textstream::TextReader;
let mut f = File::open("shiftjis.txt")?;
let mut reader = TextReader::new(f, encoding_from_whatwg_label("shiftjis").unwrap(), DecoderTrap::Strict);
Source

pub fn from_bufreader( bufreader: BufReader<R>, encoding: &dyn Encoding, trap: DecoderTrap, ) -> TextReader<R>

Creates a new TextReader from BufReader.

§Examples
extern crate textstream;
extern crate encoding;
use std::fs::File;
use std::io::BufReader;
use encoding::label::encoding_from_whatwg_label;
use encoding::{DecoderTrap, Encoding};
use textstream::TextReader;
let mut f = BufReader::new(File::open("shiftjis.txt")?);
let mut reader = TextReader::new(f, encoding_from_whatwg_label("shiftjis").unwrap(), DecoderTrap::Strict);
Source

pub fn get_bufreader(&self) -> &BufReader<R>

Gets a reference to the underlying text reader. It is inadvisable to directly read from the underlying reader.

Source

pub fn get_bufreader_mut(&mut self) -> &BufReader<R>

Gets a mutable reference to the underlying text reader. It is inadvisable to directly read from the underlying reader.

Source

pub fn into_bufreader(self) -> BufReader<R>

Unwraps this TextReader, returning the underlying reader. Note that any leftover data in the internal chunk is lost.

Source

pub fn get_decoder(&self) -> &dyn RawDecoder

Gets a reference to the underlying decoder.

Source

pub fn get_decoder_mut(&mut self) -> &mut dyn RawDecoder

Gets a mutable reference to the underlying decoder.

Source

pub fn into_decoder(self) -> Box<dyn RawDecoder>

Unwraps this TextReader, returning the underlying decoder.

Source

pub fn read_to_end(&mut self, buf: &mut String) -> Result<usize>

Read decoded text until file end, placing them into buf. If successful, this function will return the total number of bytes read.

§Examples:
extern crate textstream;
extern crate encoding;
use std::fs::File;
use std::io::BufReader;
use textstream::TextReader;
use encoding::label::encoding_from_whatwg_label;
use encoding::{DecoderTrap, Encoding};
let mut f = BufReader::new(File::open("shiftjis.txt")?);
let mut reader = TextReader::new(f, encoding_from_whatwg_label("shiftjis").unwrap(), DecoderTrap::Strict);
let mut s = String::new();
reader.read_to_end(&mut s)?;
Source

pub fn read_line(&mut self, buf: &mut String) -> Result<usize>

Read decoded text until file end, placing them into buf. If successful, this function will return the total number of bytes read.

§Examples:
extern crate textstream;
extern crate encoding;
use std::fs::File;
use std::io::BufReader;
use encoding::label::encoding_from_whatwg_label;
use encoding::{DecoderTrap, Encoding};
use textstream::TextReader;
let mut f = BufReader::new(File::open("shiftjis.txt")?);
let mut reader = TextReader::new(f, encoding_from_whatwg_label("shiftjis").unwrap(), DecoderTrap::Strict);
let mut s = String::new();
reader.read_line(&mut s)?;
Source

pub fn lines(self) -> Lines<R>

Returns an iterator over the lines of this reader. The iterator returned from this function will yield instances of textstream::Result<String>. Each string will not have a newline byte (the 0xA byte) or CRLF (0xD, 0xA bytes) at the end.

Auto Trait Implementations§

§

impl<R> Freeze for TextReader<R>
where R: Freeze,

§

impl<R> !RefUnwindSafe for TextReader<R>

§

impl<R> !Send for TextReader<R>

§

impl<R> !Sync for TextReader<R>

§

impl<R> Unpin for TextReader<R>
where R: Unpin,

§

impl<R> !UnwindSafe for TextReader<R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.