Struct ropey::Rope [] [src]

pub struct Rope { /* fields omitted */ }

A utf8 text rope.

Rope's atomic unit of data is Unicode scalar values (or chars in Rust). Except where otherwise documented, all methods that index into a rope or return an index into a rope do so by char index. This makes the API's intuitive and prevents accidentally creating a Rope with invalid utf8 data.

The primary editing operations available for Rope are insertion of text, deletion of text, splitting a Rope in two, and appending one Rope to another. For example:

let mut rope = Rope::from_str("Hello みんなさん!");
rope.remove(6, 11);
rope.insert(6, "world");

assert_eq!(rope, "Hello world!");

Cloning Rope's is extremely cheap, taking only a few instructions and 8 bytes of memory, regardless of text size. This is accomplished by data sharing between Rope clones, and the memory used by clones only grows incrementally as the their contents diverge due to edits. All of this is thread safe, and clones can be sent freely between threads.

Rope tracks line endings and has efficient API's for working with lines. You can convert between char and line index, determining which line a given char is on or the char index of the beginning of a line:

let rope = Rope::from_str("Hello individual!\nHow are you?\nThis text has multiple lines!");

assert_eq!(rope.char_to_line(5), 0);
assert_eq!(rope.char_to_line(21), 1);

assert_eq!(rope.line_to_char(0), 0);
assert_eq!(rope.line_to_char(1), 18);
assert_eq!(rope.line_to_char(2), 31);

Rope is written to be fast and memory efficient. All editing and query operations execute in worst-case O(log N) time in the length of the text. (If they don't, file a bug!) It is designed to work efficiently even for huge (in the gigabytes) and pathological (all on one line) texts. It should be able to handle just about anything you can throw at it.

Methods

impl Rope
[src]

[src]

Creates an empty Rope.

[src]

Creates a Rope from a string slice.

[src]

Creates a Rope from the output of a reader.

Errors

  • If the reader returns an error, from_reader stops and returns that error.
  • If non-utf8 data is encountered, an IO error with kind InvalidData is returned.

Note: some data from the reader is likely consumed even if there is an error.

[src]

Total number of bytes in the Rope.

[src]

Total number of chars in the Rope.

[src]

Total number of lines in the Rope.

[src]

Inserts text at char index char_idx.

Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

[src]

Removes the text in char range start..end.

Panics

Panics if start is greater than end or end is out of bounds (i.e. end > len_chars()).

[src]

Splits the Rope at char_idx, returning the right part of the split.

Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

[src]

Appends a Rope to the end of this one, consuming the other Rope.

[src]

Returns the line index of the given char.

Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

[src]

Returns the char index of the start of the given line.

Note: lines are zero-indexed.

Panics

Panics if line_idx is out of bounds (i.e. line_idx > len_lines()).

[src]

Returns the char at char_idx.

Panics

Panics if char_idx is out of bounds (i.e. char_idx >= len_chars()).

[src]

Returns the line at line_idx.

Note: lines are zero-indexed.

Panics

Panics if line_idx is out of bounds (i.e. line_idx >= len_lines()).

[src]

Returns whether char_idx is a grapheme cluster boundary or not.

Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

[src]

Returns the char index of the grapheme cluster boundary to the left of char_idx.

This excludes any boundary that might be at char_idx itself, unless char_idx is at the beginning of the rope.

Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

[src]

Returns the char index of the grapheme cluster boundary to the right of char_idx.

This excludes any boundary that might be at char_idx itself, unless char_idx is at the end of the rope.

Panics

Panics if char_idx is out of bounds (i.e. char_idx > len_chars()).

[src]

Returns an immutable slice of the Rope in the char range start..end.

Panics

Panics if start is greater than end or end is out of bounds (i.e. end > len_chars()).

[src]

Creates an iterator over the bytes of the Rope.

[src]

Creates an iterator over the chars of the Rope.

[src]

Creates an iterator over the grapheme clusters of the Rope.

[src]

Creates an iterator over the lines of the Rope.

[src]

Creates an iterator over the chunks of the Rope.

[src]

Returns the entire text of the Rope as a newly allocated String.

[src]

Returns a slice to the entire contents of the Rope.

Mainly just a convenience method, since the RangeArgument trait isn't stabilized yet.

Trait Implementations

impl Clone for Rope
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Rope
[src]

[src]

Formats the value using the given formatter.

impl Display for Rope
[src]

[src]

Formats the value using the given formatter. Read more

impl Default for Rope
[src]

[src]

Returns the "default value" for a type. Read more

impl<'a> PartialEq<Rope> for Rope
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a> PartialEq<&'a str> for Rope
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<'a> PartialEq<RopeSlice<'a>> for Rope
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.