Struct uu_tail::chunks::LinesChunk

source ·
pub struct LinesChunk { /* private fields */ }
Expand description

Works similar to a BytesChunk but also stores the number of lines encountered in the current buffer. The size of the buffer is limited to a fixed size number of bytes.

Implementations§

source§

impl LinesChunk

source

pub fn new(delimiter: u8) -> Self

source

pub fn has_data(&self) -> bool

Returns true if this buffer has stored any bytes.

Examples
let mut chunk = LinesChunk::new(b'\n');
assert!(!chunk.has_data());

chunk.buffer[0] = 1;
assert!(!chunk.has_data());

chunk.bytes = 1;
assert!(chunk.has_data());
source

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

Returns this buffer safely. See BytesChunk::get_buffer

returns: &u8 with length self.bytes

source

pub fn get_buffer_with(&self, offset: usize) -> &[u8]

Returns this buffer safely with an offset applied. See BytesChunk::get_buffer_with.

returns: &u8 with length self.bytes - offset

source

pub fn get_lines(&self) -> usize

Return the number of lines the buffer contains. self.lines needs to be set before the call to this function returns the correct value. If the calculation of lines is needed then use self.count_lines.

source

pub fn fill(&mut self, filehandle: &mut impl BufRead) -> UResult<Option<usize>>

Fills self.buffer with maximal BUFFER_SIZE number of bytes, draining the reader by that number of bytes. This function works like the BytesChunk::fill function besides that this function also counts and stores the number of lines encountered while reading from the filehandle.

source

pub fn print_lines(&self, writer: &mut impl Write, offset: usize) -> UResult<()>

Print the bytes contained in this buffer calculated with the given offset in number of lines.

Arguments
  • writer: must implement Write
  • offset: An offset in number of lines.
source

pub fn print_bytes(&self, writer: &mut impl Write, offset: usize) -> UResult<()>

Print the bytes contained in this buffer beginning from the given offset in number of bytes.

Arguments
  • writer: must implement Write
  • offset: An offset in number of bytes.

Trait Implementations§

source§

impl Debug for LinesChunk

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.