ReadableDocument

Trait ReadableDocument 

Source
pub trait ReadableDocument {
    // Required methods
    fn read_forward(&self, off: usize) -> &[u8] ;
    fn read_backward(&self, off: usize) -> &[u8] ;
}
Expand description

An abstraction over reading from text containers.

Required Methods§

Source

fn read_forward(&self, off: usize) -> &[u8]

Read some bytes starting at (including) the given absolute offset.

§Warning
  • Be lenient on inputs:
    • The given offset may be out of bounds and you MUST clamp it.
    • You should not assume that offsets are at grapheme cluster boundaries.
  • Be strict on outputs:
    • You MUST NOT break grapheme clusters across chunks.
    • You MUST NOT return an empty slice unless the offset is at or beyond the end.
Source

fn read_backward(&self, off: usize) -> &[u8]

Read some bytes before (but not including) the given absolute offset.

§Warning
  • Be lenient on inputs:
    • The given offset may be out of bounds and you MUST clamp it.
    • You should not assume that offsets are at grapheme cluster boundaries.
  • Be strict on outputs:
    • You MUST NOT break grapheme clusters across chunks.
    • You MUST NOT return an empty slice unless the offset is zero.

Implementations on Foreign Types§

Source§

impl ReadableDocument for &[u8]

Source§

fn read_forward(&self, off: usize) -> &[u8]

Source§

fn read_backward(&self, off: usize) -> &[u8]

Source§

impl ReadableDocument for String

Source§

fn read_forward(&self, off: usize) -> &[u8]

Source§

fn read_backward(&self, off: usize) -> &[u8]

Source§

impl ReadableDocument for PathBuf

Source§

fn read_forward(&self, off: usize) -> &[u8]

Source§

fn read_backward(&self, off: usize) -> &[u8]

Implementors§