pub enum Rope {
Node(usize, Arc<Rope>, Arc<Rope>),
Leaf(Arc<String>),
}Variants§
Implementations§
Source§impl Rope
impl Rope
Sourcepub fn new() -> Self
pub fn new() -> Self
§Examples
use persistent_rope::Rope;
let rope = Rope::new();
assert_eq!(&rope, "");Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(rope.len(), 13);Sourcepub fn bytes_len(&self) -> usize
pub fn bytes_len(&self) -> usize
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(rope.bytes_len(), 13);Sourcepub fn chars_len(&self) -> usize
pub fn chars_len(&self) -> usize
§Examples
use persistent_rope::Rope;
let rope = Rope::from("長さ");
assert_eq!(rope.chars_len(), 2);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert!(!rope.is_empty());Sourcepub fn height(&self) -> usize
pub fn height(&self) -> usize
§Examples
use persistent_rope::Rope;
let a = Rope::from("Hello");
let b = a.insert_at_byte(5, ", world!");
assert_eq!(b.height(), 2);Sourcepub fn count_lines(&self) -> usize
pub fn count_lines(&self) -> usize
§Examples
use persistent_rope::Rope;
let a = Rope::from("Hello,\n");
let b = a.insert_at_byte(5, "world!\n");
assert_eq!(b.count_lines(), 2);Sourcepub fn insert_at_byte<T>(&self, index: usize, value: T) -> Rope
pub fn insert_at_byte<T>(&self, index: usize, value: T) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Helloworld!");
assert_eq!(&rope.insert_at_byte(5, ", "), "Hello, world!");Sourcepub fn insert<T>(&self, index: usize, value: T) -> Rope
pub fn insert<T>(&self, index: usize, value: T) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("長さ");
assert_eq!(&rope.insert(1, ", "), "長, さ");Sourcepub fn insert_range_byte<T>(&self, range: Range<usize>, value: T) -> Rope
pub fn insert_range_byte<T>(&self, range: Range<usize>, value: T) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello world");
assert_eq!(&rope.insert_range_byte(5..6, ", "), "Hello, world");
assert_eq!(&rope.insert_range_byte(0..0, "!"), "!Hello world");
assert_eq!(&rope.insert_range_byte(11..11, "!"), "Hello world!");Sourcepub fn insert_range<T>(&self, range: Range<usize>, value: T) -> Rope
pub fn insert_range<T>(&self, range: Range<usize>, value: T) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("長 さ");
assert_eq!(&rope.insert_range(1..2, ", "), "長, さ");
assert_eq!(&rope.insert_range(0..0, "!"), "!長 さ");
assert_eq!(&rope.insert_range(3..3, "!"), "長 さ!");Sourcepub fn insert_char_at_byte(&self, index: usize, ch: char) -> Rope
pub fn insert_char_at_byte(&self, index: usize, ch: char) -> Rope
§Examples
use persistent_rope::Rope;
let a = Rope::from("Hello").concat(" world");
let b = a.insert_char_at_byte(5, ',');
let c = b.insert_char_at_byte(12, '!');
assert_eq!(&b, "Hello, world");
assert_eq!(&c, "Hello, world!");Sourcepub fn insert_char(&self, index: usize, ch: char) -> Rope
pub fn insert_char(&self, index: usize, ch: char) -> Rope
§Examples
use persistent_rope::Rope;
let a = Rope::from("長").concat("さ");
let b = a.insert_char(1, ',');
let c = b.insert_char(3, '!');
assert_eq!(&b, "長,さ");
assert_eq!(&c, "長,さ!");Sourcepub fn remove_range_byte(&self, range: Range<usize>) -> Rope
pub fn remove_range_byte(&self, range: Range<usize>) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(&rope.remove_range_byte(5..13), "Hello");Sourcepub fn remove_range(&self, range: Range<usize>) -> Rope
pub fn remove_range(&self, range: Range<usize>) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("長 さ");
assert_eq!(&rope.remove_range(1..2), "長さ");Sourcepub fn remove_at_byte(&self, index: usize) -> Rope
pub fn remove_at_byte(&self, index: usize) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(&rope.remove_at_byte(12), "Hello, world");
assert_eq!(&rope.remove_at_byte(5), "Hello world!");Sourcepub fn remove(&self, index: usize) -> Rope
pub fn remove(&self, index: usize) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("長さ");
assert_eq!(&rope.remove(0), "さ");
assert_eq!(&rope.remove(1), "長");Sourcepub fn split_at_byte(&self, index: usize) -> (Rope, Rope)
pub fn split_at_byte(&self, index: usize) -> (Rope, Rope)
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
let (left, right) = rope.split_at_byte(7);
assert_eq!(&left, "Hello, ");
assert_eq!(&right, "world!");
let rope = Rope::new();
let (left, right) = rope.split_at_byte(0);
assert_eq!(&left, "");
assert_eq!(&right, "");Sourcepub fn split(&self, index: usize) -> (Rope, Rope)
pub fn split(&self, index: usize) -> (Rope, Rope)
§Examples
use persistent_rope::Rope;
let rope = Rope::from("長さ");
let (left, right) = rope.split(1);
assert_eq!(&left, "長");
assert_eq!(&right, "さ");Sourcepub fn concat<T>(&self, value: T) -> Rope
pub fn concat<T>(&self, value: T) -> Rope
§Examples
use persistent_rope::Rope;
let left = Rope::from("Hello, ");
let right = Rope::from("world!");
assert_eq!(&left.concat(right), "Hello, world!");Sourcepub fn concat_char(&self, ch: char) -> Rope
pub fn concat_char(&self, ch: char) -> Rope
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello").concat(", world");
println!("{:?}", rope);
assert_eq!(&rope.concat_char('!'), "Hello, world!");Sourcepub fn char_at(&self, index: usize) -> Option<char>
pub fn char_at(&self, index: usize) -> Option<char>
§Examples
use persistent_rope::Rope;
let rope = Rope::from("長").concat(", さ!");
assert_eq!(rope.char_at(0), Some('長'));
assert_eq!(rope.char_at(1), Some(','));
assert_eq!(rope.char_at(2), Some(' '));
assert_eq!(rope.char_at(3), Some('さ'));
assert_eq!(rope.char_at(4), Some('!'));Sourcepub fn chunks(&self) -> Chunks<'_> ⓘ
pub fn chunks(&self) -> Chunks<'_> ⓘ
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello").concat(", world!");
assert_eq!(rope.chunks().collect::<Vec<&String>>(), ["Hello", ", world!"].to_vec());Sourcepub fn bytes(&self) -> Bytes<'_> ⓘ
pub fn bytes(&self) -> Bytes<'_> ⓘ
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello");
assert_eq!(rope.bytes().collect::<Vec<u8>>(), [72, 101, 108, 108, 111].to_vec());Sourcepub fn chars(&self) -> Chars<'_> ⓘ
pub fn chars(&self) -> Chars<'_> ⓘ
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello");
assert_eq!(rope.chars().collect::<Vec<char>>(), ['H', 'e', 'l', 'l', 'o'].to_vec());Sourcepub fn lines(&self) -> Lines<'_> ⓘ
pub fn lines(&self) -> Lines<'_> ⓘ
§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello\n world!");
let lines = rope.lines().collect::<Vec<String>>();
assert_eq!(lines.get(0), Some(&String::from("Hello")));
assert_eq!(lines.get(1), Some(&String::from(" world!")));pub fn iter(&self) -> Chars<'_> ⓘ
Trait Implementations§
Source§impl<'a, T> Add<T> for &'a Rope
impl<'a, T> Add<T> for &'a Rope
Source§impl<T> Add<T> for Rope
impl<T> Add<T> for Rope
Source§impl<'a> IntoIterator for &'a Rope
impl<'a> IntoIterator for &'a Rope
Source§impl Ord for Rope
impl Ord for Rope
Source§impl<'a> PartialEq<&'a str> for Rope
impl<'a> PartialEq<&'a str> for Rope
Source§impl PartialEq<String> for Rope
impl PartialEq<String> for Rope
Source§impl PartialEq<str> for Rope
impl PartialEq<str> for Rope
Source§impl PartialOrd for Rope
impl PartialOrd for Rope
impl Eq for Rope
impl Send for Rope
impl StructuralPartialEq for Rope
impl Sync for Rope
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more