use crate::api::*;
pub trait Utf8Rope {
fn from_str(string: &str) -> Self;
fn to_string_lossy(&self) -> String;
}
impl<R: Default+RopeMut<Cell=u8>> Utf8Rope for R {
fn from_str(string: &str) -> Self {
let mut new_rope = Self::default();
new_rope.replace(0..0, string.bytes());
new_rope
}
fn to_string_lossy(&self) -> String {
let bytes = self.read_cells(0..self.len())
.map(|byte| *byte)
.collect::<Vec<_>>();
String::from_utf8_lossy(&bytes).into()
}
}