use crate::{ChUnit, ColIndex, ColWidth, ContainsWideSegments, Seg, SegContent, SegIndex,
SegLength};
use std::fmt::Display;
pub trait GraphemeString {
type SegmentIterator<'a>: Iterator<Item = Seg> + 'a
where
Self: 'a;
type StringSlice<'a>: AsRef<str> + Display
where
Self: 'a;
fn as_str(&self) -> &str;
fn segments(&self) -> &[Seg];
fn display_width(&self) -> ColWidth;
fn segment_count(&self) -> SegLength;
fn byte_size(&self) -> ChUnit;
fn get_seg(&self, index: SegIndex) -> Option<Seg>;
fn check_is_in_middle_of_grapheme(&self, col: ColIndex) -> Option<Seg>;
fn get_seg_at(&self, col: ColIndex) -> Option<SegContent<'_>>;
fn get_seg_right_of(&self, col: ColIndex) -> Option<SegContent<'_>>;
fn get_seg_left_of(&self, col: ColIndex) -> Option<SegContent<'_>>;
fn get_seg_at_end(&self) -> Option<SegContent<'_>>;
fn clip(&self, start_col: ColIndex, width: ColWidth) -> Self::StringSlice<'_>;
fn trunc_end_to_fit(&self, width: ColWidth) -> Self::StringSlice<'_>;
fn trunc_end_by(&self, width: ColWidth) -> Self::StringSlice<'_>;
fn trunc_start_by(&self, width: ColWidth) -> Self::StringSlice<'_>;
fn segments_iter(&self) -> Self::SegmentIterator<'_>;
fn is_empty(&self) -> bool;
fn last(&self) -> Option<Seg>;
fn contains_wide_segments(&self) -> ContainsWideSegments;
}
pub trait GraphemeStringMut: GraphemeString {
type MutResult;
fn insert_text(&mut self, col: ColIndex, text: &str) -> Option<Self::MutResult>;
fn delete_range(&mut self, start: ColIndex, end: ColIndex)
-> Option<Self::MutResult>;
fn replace_range(
&mut self,
start: ColIndex,
end: ColIndex,
text: &str,
) -> Option<Self::MutResult>;
fn truncate(&mut self, col: ColIndex) -> Option<Self::MutResult>;
}