Struct ropey::RopeSlice [−][src]
pub struct RopeSlice<'a>(_);
An immutable view into part of a Rope
.
Methods
impl<'a> RopeSlice<'a>
[src]
impl<'a> RopeSlice<'a>
pub fn from_str(text: &str) -> RopeSlice
[src]
pub fn from_str(text: &str) -> RopeSlice
Creates a RopeSlice
from a string slice.
The resulting RopeSlice
is very lightweight, and simply refers
directly to the string slice.
This is primarily intended for avoiding the performance overhead of a
full slice()
operation when relevant. The slice()
method is
comparatively cheap, but it may nevertheless be too expensive for
some tight inner loops because of the tree traversal it typically has
to do.
A good example of this method's usage is in examples/graphemes_iter.rs
,
where it is used to significantly speed up the graphemes iterator.
pub fn len_bytes(&self) -> usize
[src]
pub fn len_bytes(&self) -> usize
Total number of bytes in the RopeSlice
.
pub fn len_chars(&self) -> usize
[src]
pub fn len_chars(&self) -> usize
Total number of chars in the RopeSlice
.
pub fn len_lines(&self) -> usize
[src]
pub fn len_lines(&self) -> usize
Total number of lines in the RopeSlice
.
pub fn byte_to_char(&self, byte_idx: usize) -> usize
[src]
pub fn byte_to_char(&self, byte_idx: usize) -> usize
Returns the char index of the given byte.
Panics
Panics if byte_idx
is out of bounds (i.e. byte_idx > len_bytes()
).
pub fn byte_to_line(&self, byte_idx: usize) -> usize
[src]
pub fn byte_to_line(&self, byte_idx: usize) -> usize
Returns the line index of the given byte.
Notes:
- Lines are zero-indexed.
- If
byte_idx
is one-past-the-end, then one-past-the-end line index is returned. This is mainly unintuitive for empty ropes, which will return a line index of 1 for abyte_idx
of zero. Otherwise it behaves as expected.
Panics
Panics if byte_idx
is out of bounds (i.e. byte_idx > len_bytes()
).
pub fn char_to_byte(&self, char_idx: usize) -> usize
[src]
pub fn char_to_byte(&self, char_idx: usize) -> usize
Returns the byte index of the given char.
Panics
Panics if char_idx
is out of bounds (i.e. char_idx > len_chars()
).
pub fn char_to_line(&self, char_idx: usize) -> usize
[src]
pub fn char_to_line(&self, char_idx: usize) -> usize
Returns the line index of the given char.
Notes:
- Lines are zero-indexed.
- If
char_idx
is one-past-the-end, then one-past-the-end line index is returned. This is mainly unintuitive for empty ropes, which will return a line index of 1 for achar_idx
of zero. Otherwise it behaves as expected.
Panics
Panics if char_idx
is out of bounds (i.e. char_idx > len_chars()
).
pub fn line_to_byte(&self, line_idx: usize) -> usize
[src]
pub fn line_to_byte(&self, line_idx: usize) -> usize
Returns the byte index of the start of the given line.
Notes:
- Lines are zero-indexed.
line_idx
can be one-past-the-end, which will return one-past-the-end byte index.
Panics
Panics if line_idx
is out of bounds (i.e. line_idx > len_lines()
).
pub fn line_to_char(&self, line_idx: usize) -> usize
[src]
pub fn line_to_char(&self, line_idx: usize) -> usize
Returns the char index of the start of the given line.
Notes:
- Lines are zero-indexed.
line_idx
can be one-past-the-end, which will return one-past-the-end char index.
Panics
Panics if line_idx
is out of bounds (i.e. line_idx > len_lines()
).
pub fn char(&self, char_idx: usize) -> char
[src]
pub fn char(&self, char_idx: usize) -> char
Returns the char at char_idx
.
Panics
Panics if char_idx
is out of bounds (i.e. char_idx >= len_chars()
).
pub fn line(&self, line_idx: usize) -> RopeSlice<'a>
[src]
pub fn line(&self, line_idx: usize) -> RopeSlice<'a>
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()
).
pub fn chunk_at_byte(&self, byte_idx: usize) -> (&str, usize, usize)
[src]
pub fn chunk_at_byte(&self, byte_idx: usize) -> (&str, usize, usize)
Returns the chunk containing the given byte index, along with the byte and char indices of the beginning of the chunk.
The return value is organized as (chunk, chunk_byte_idx, chunk_char_idx)
.
Panics
Panics if byte_idx
is out of bounds (i.e. byte_idx > len_bytes()
).
pub fn chunk_at_char(&self, char_idx: usize) -> (&str, usize, usize)
[src]
pub fn chunk_at_char(&self, char_idx: usize) -> (&str, usize, usize)
Returns the chunk containing the given char index, along with the byte and char indices of the beginning of the chunk.
The return value is organized as (chunk, chunk_byte_idx, chunk_char_idx)
.
Panics
Panics if char_idx
is out of bounds (i.e. char_idx > len_chars()
).
pub fn as_str(&self) -> Option<&str>
[src]
pub fn as_str(&self) -> Option<&str>
Returns the entire contents of the RopeSlice
as a str
slice if
possible.
Note that this method will typically fail, since the contents of a rope is generally not contiguous in memory.
This is intended for optimizing cases where the slice is a small part of the text (around the size of a few characters or words) and therefore has a high chance of being contiguous in memory.
pub fn slice<R: CharIdxRange>(&self, range: R) -> Self
[src]
pub fn slice<R: CharIdxRange>(&self, range: R) -> Self
Returns a sub-slice of the RopeSlice
in the given char index range.
Uses range syntax, e.g. 2..7
, 2..
, etc. The range is in char
indices.
Panics
Panics if the start of the range is greater than the end, or the end
is out of bounds (i.e. end > len_chars()
).
ⓘImportant traits for Bytes<'a>pub fn bytes(&self) -> Bytes<'a>
[src]
pub fn bytes(&self) -> Bytes<'a>
Creates an iterator over the bytes of the RopeSlice
.
ⓘImportant traits for Chars<'a>pub fn chars(&self) -> Chars<'a>
[src]
pub fn chars(&self) -> Chars<'a>
Creates an iterator over the chars of the RopeSlice
.
ⓘImportant traits for Lines<'a>pub fn lines(&self) -> Lines<'a>
[src]
pub fn lines(&self) -> Lines<'a>
Creates an iterator over the lines of the RopeSlice
.
ⓘImportant traits for Chunks<'a>pub fn chunks(&self) -> Chunks<'a>
[src]
pub fn chunks(&self) -> Chunks<'a>
Creates an iterator over the chunks of the RopeSlice
.
pub fn to_string(&self) -> String
[src]
pub fn to_string(&self) -> String
Returns the entire text of the RopeSlice
as a newly allocated String
.
pub fn to_rope(&self) -> Rope
[src]
pub fn to_rope(&self) -> Rope
Creates a new Rope
from the contents of the RopeSlice
.
Trait Implementations
impl<'a> Copy for RopeSlice<'a>
[src]
impl<'a> Copy for RopeSlice<'a>
impl<'a> Clone for RopeSlice<'a>
[src]
impl<'a> Clone for RopeSlice<'a>
fn clone(&self) -> RopeSlice<'a>
[src]
fn clone(&self) -> RopeSlice<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a> Debug for RopeSlice<'a>
[src]
impl<'a> Debug for RopeSlice<'a>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a> Display for RopeSlice<'a>
[src]
impl<'a> Display for RopeSlice<'a>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a, 'b> PartialEq<RopeSlice<'b>> for RopeSlice<'a>
[src]
impl<'a, 'b> PartialEq<RopeSlice<'b>> for RopeSlice<'a>
fn eq(&self, other: &RopeSlice<'b>) -> bool
[src]
fn eq(&self, other: &RopeSlice<'b>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'b> PartialEq<&'b str> for RopeSlice<'a>
[src]
impl<'a, 'b> PartialEq<&'b str> for RopeSlice<'a>
fn eq(&self, other: &&'b str) -> bool
[src]
fn eq(&self, other: &&'b str) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'b> PartialEq<RopeSlice<'a>> for &'b str
[src]
impl<'a, 'b> PartialEq<RopeSlice<'a>> for &'b str
fn eq(&self, other: &RopeSlice<'a>) -> bool
[src]
fn eq(&self, other: &RopeSlice<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> PartialEq<str> for RopeSlice<'a>
[src]
impl<'a> PartialEq<str> for RopeSlice<'a>
fn eq(&self, other: &str) -> bool
[src]
fn eq(&self, other: &str) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> PartialEq<RopeSlice<'a>> for str
[src]
impl<'a> PartialEq<RopeSlice<'a>> for str
fn eq(&self, other: &RopeSlice<'a>) -> bool
[src]
fn eq(&self, other: &RopeSlice<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> PartialEq<String> for RopeSlice<'a>
[src]
impl<'a> PartialEq<String> for RopeSlice<'a>
fn eq(&self, other: &String) -> bool
[src]
fn eq(&self, other: &String) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> PartialEq<RopeSlice<'a>> for String
[src]
impl<'a> PartialEq<RopeSlice<'a>> for String
fn eq(&self, other: &RopeSlice<'a>) -> bool
[src]
fn eq(&self, other: &RopeSlice<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'b> PartialEq<Cow<'b, str>> for RopeSlice<'a>
[src]
impl<'a, 'b> PartialEq<Cow<'b, str>> for RopeSlice<'a>
fn eq(&self, other: &Cow<'b, str>) -> bool
[src]
fn eq(&self, other: &Cow<'b, str>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'b> PartialEq<RopeSlice<'a>> for Cow<'b, str>
[src]
impl<'a, 'b> PartialEq<RopeSlice<'a>> for Cow<'b, str>
fn eq(&self, other: &RopeSlice<'a>) -> bool
[src]
fn eq(&self, other: &RopeSlice<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> PartialEq<Rope> for RopeSlice<'a>
[src]
impl<'a> PartialEq<Rope> for RopeSlice<'a>
fn eq(&self, other: &Rope) -> bool
[src]
fn eq(&self, other: &Rope) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a> PartialEq<RopeSlice<'a>> for Rope
[src]
impl<'a> PartialEq<RopeSlice<'a>> for Rope