Enum Rope

Source
pub enum Rope {
    Node(usize, Arc<Rope>, Arc<Rope>),
    Leaf(Arc<String>),
}

Variants§

§

Node(usize, Arc<Rope>, Arc<Rope>)

§

Leaf(Arc<String>)

Implementations§

Source§

impl Rope

Source

pub fn new() -> Self

§Examples
use persistent_rope::Rope;
let rope = Rope::new();
assert_eq!(&rope, "");
Source

pub fn len(&self) -> usize

§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(rope.len(), 13);
Source

pub fn bytes_len(&self) -> usize

§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(rope.bytes_len(), 13);
Source

pub fn chars_len(&self) -> usize

§Examples
use persistent_rope::Rope;
let rope = Rope::from("長さ");
assert_eq!(rope.chars_len(), 2);
Source

pub fn is_empty(&self) -> bool

§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert!(!rope.is_empty());
Source

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);
Source

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);
Source

pub fn insert_at_byte<T>(&self, index: usize, value: T) -> Rope
where T: Into<Rope>,

§Examples
use persistent_rope::Rope;
let rope = Rope::from("Helloworld!");
assert_eq!(&rope.insert_at_byte(5, ", "), "Hello, world!");
Source

pub fn insert<T>(&self, index: usize, value: T) -> Rope
where T: Into<Rope>,

§Examples
use persistent_rope::Rope;
let rope = Rope::from("長さ");
assert_eq!(&rope.insert(1, ", "), "長, さ");
Source

pub fn insert_range_byte<T>(&self, range: Range<usize>, value: T) -> Rope
where T: Into<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!");
Source

pub fn insert_range<T>(&self, range: Range<usize>, value: T) -> Rope
where T: Into<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, "!"), "長 さ!");
Source

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!");
Source

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, "長,さ!");
Source

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");
Source

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), "長さ");
Source

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!");
Source

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), "長");
Source

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, "");
Source

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, "さ");
Source

pub fn concat<T>(&self, value: T) -> Rope
where T: Into<Rope>,

§Examples
use persistent_rope::Rope;
let left = Rope::from("Hello, ");
let right = Rope::from("world!");
assert_eq!(&left.concat(right), "Hello, world!");
Source

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!");
Source

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('!'));
Source

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());
Source

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());
Source

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());
Source

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!")));
Source

pub fn iter(&self) -> Chars<'_>

Trait Implementations§

Source§

impl<'a, T> Add<T> for &'a Rope
where T: Into<Rope>,

Source§

fn add(self, other: T) -> Self::Output

§Examples
use persistent_rope::Rope;
let a = Rope::from("Hello");
let b = Rope::from(", world!");
assert_eq!(&a + &b, "Hello, world!");
assert_eq!(&a + b.clone(), "Hello, world!");
assert_eq!(a.clone() + &b, "Hello, world!");
Source§

type Output = Rope

The resulting type after applying the + operator.
Source§

impl<T> Add<T> for Rope
where T: Into<Rope>,

Source§

fn add(self, other: T) -> Self::Output

§Examples
use persistent_rope::Rope;
let a = Rope::from("Hello");
let b = Rope::from(", world!");
assert_eq!(a.clone() + b, "Hello, world!");
assert_eq!(a + ", world!", "Hello, world!");
Source§

type Output = Rope

The resulting type after applying the + operator.
Source§

impl Clone for Rope

Source§

fn clone(&self) -> Rope

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a Arc<Rope>> for Rope

Source§

fn from(rope: &'a Arc<Rope>) -> Rope

Converts to this type from the input type.
Source§

impl<'a> From<&'a Rope> for Bytes<'a>

Source§

fn from(rope: &'a Rope) -> Bytes<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&'a Rope> for Chars<'a>

Source§

fn from(rope: &'a Rope) -> Chars<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&'a Rope> for Chunks<'a>

Source§

fn from(rope: &'a Rope) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Rope> for Lines<'a>

Source§

fn from(rope: &'a Rope) -> Lines<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&'a Rope> for Rope

Source§

fn from(rope: &'a Rope) -> Rope

Converts to this type from the input type.
Source§

impl<'a> From<&'a String> for Rope

Source§

fn from(string: &'a String) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Rope

Source§

fn from(string: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<Arc<Rope>> for Rope

Source§

fn from(arc: Arc<Rope>) -> Rope

Converts to this type from the input type.
Source§

impl From<String> for Rope

Source§

fn from(string: String) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Rope

Source§

fn from(ch: char) -> Self

Converts to this type from the input type.
Source§

impl Hash for Rope

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Into<String> for Rope

Source§

fn into(self) -> String

Converts this type into the (usually inferred) input type.
Source§

impl<'a> IntoIterator for &'a Rope

Source§

type Item = char

The type of the elements being iterated over.
Source§

type IntoIter = Chars<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for Rope

Source§

fn cmp(&self, other: &Rope) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a> PartialEq<&'a str> for Rope

Source§

fn eq(&self, other: &&'a str) -> bool

§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(&rope, "Hello, world!");
assert_ne!(&rope, "Hello!");
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for Rope

Source§

fn eq(&self, other: &String) -> bool

§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(&rope, &String::from("Hello, world!"));
assert_ne!(&rope, &String::from("Hello!"));
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for Rope

Source§

fn eq(&self, other: &str) -> bool

§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(rope, "Hello, world!");
assert_ne!(rope, "Hello!");
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Rope

Source§

fn eq(&self, other: &Rope) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Rope

Source§

fn partial_cmp(&self, other: &Rope) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToString for Rope

Source§

fn to_string(&self) -> String

§Examples
use persistent_rope::Rope;
let rope = Rope::from("Hello, world!");
assert_eq!(rope.to_string(), "Hello, world!");
Source§

impl Eq for Rope

Source§

impl Send for Rope

Source§

impl StructuralPartialEq for Rope

Source§

impl Sync for Rope

Auto Trait Implementations§

§

impl Freeze for Rope

§

impl RefUnwindSafe for Rope

§

impl Unpin for Rope

§

impl UnwindSafe for Rope

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.