pub mod file;
#[cfg(feature = "vecbuffer")]
mod vecbuffer;
#[cfg(feature = "vecbuffer")]
pub use vecbuffer::*;
pub trait Buffer {
fn len(&self)
-> usize ;
fn get_tag(&self, tag: char)
-> Result<usize, &'static str> ;
fn get_matching(&self, pattern: &str, curr_line: usize, backwards: bool)
-> Result<usize, &'static str> ;
fn mark_matching(&mut self, pattern: &str, selection: (usize, usize), inverse: bool)
-> Result<(), &'static str> ;
fn get_marked(&mut self)
-> Result<Option<usize>, &'static str> ;
fn tag_line(&mut self, index: usize, tag: char)
-> Result<(), &'static str> ;
fn insert<'a>(&mut self, data: &mut dyn Iterator<Item = &'a str>, index: usize)
-> Result<(), &'static str> ;
fn cut(&mut self, selection: (usize, usize))
-> Result<(), &'static str> ;
fn change<'a>(&mut self, data: &mut dyn Iterator<Item = &'a str>, selection: (usize, usize))
-> Result<(), &'static str> ;
fn mov(&mut self, selection: (usize, usize), index: usize)
-> Result<(), &'static str> ;
fn mov_copy(&mut self, selection: (usize, usize), index: usize)
-> Result<(), &'static str> ;
fn join(&mut self, selection: (usize, usize))
-> Result<(), &'static str> ;
fn copy(&mut self, selection: (usize, usize))
-> Result<(), &'static str> ;
fn paste(&mut self, index: usize)
-> Result<usize, &'static str> ;
fn search_replace(&mut self, pattern: (&str, &str), selection: (usize, usize), global: bool)
-> Result<(usize, usize), &'static str> ;
fn read_from(&mut self, path: &str, index: Option<usize>, must_exist: bool)
-> Result<usize, &'static str> ;
fn write_to(&mut self, selection: Option<(usize, usize)>, path: &str, append: bool)
-> Result<(), &'static str> ;
fn saved(&self)
-> bool ;
fn get_selection<'a>(&'a self, selection: (usize, usize))
-> Result<Box<dyn Iterator<Item = &'a str> + 'a>, &'static str> ;
}
pub fn verify_index(
buffer: &impl Buffer,
index: usize,
) -> Result<(), &'static str> {
if index > buffer.len() { return Err(crate::error_consts::INDEX_TOO_BIG); }
Ok(())
}
pub fn verify_selection(
buffer: &impl Buffer,
selection: (usize, usize),
) -> Result<(), &'static str> {
if selection.0 > selection.1 { return Err(crate::error_consts::SELECTION_EMPTY); }
if selection.1 >= buffer.len() { return Err(crate::error_consts::INDEX_TOO_BIG); }
Ok(())
}