Struct an_rope::RopeSliceMut
[−]
[src]
pub struct RopeSliceMut<'a> { /* fields omitted */ }
An mutable borrowed slice of a Rope
.
A RopeSliceMut
represents a mutable borrowed slice of some or all the
characters in a Rope
.
Methods
impl<'a> RopeSliceMut<'a>
[src]
fn new(node: &'a mut Node, range: Range<usize>) -> Self
fn chars(&'a self) -> Box<Iterator<Item=char> + 'a>
fn char_indices(&'a self) -> Box<Iterator<Item=(usize, char)> + 'a>
fn bytes(&'a self) -> Box<Iterator<Item=u8> + 'a>
fn split_whitespace(&'a self) -> Box<Iterator<Item=&'a str> + 'a>
fn len(&self) -> usize
Returns the length of self.
This length is in bytes, not chars or graphemes. In other words, it may not be what a human considers the length of the string.
fn is_empty(&self) -> bool
Returns true
if this RopeSliceMut
is empty.
Examples
A RopeSliceMut
into an empty rope should be empty:
use an_rope::Rope; let mut an_empty_rope = Rope::new(); assert!(an_empty_rope.slice_mut(0..0).is_empty());
A RopeSliceMut
that contains no characters should be empty,
even fi the sliced Rope
is not empty:
use an_rope::Rope; let mut an_rope = Rope::from("a string that is not empty"); assert!(an_rope.slice_mut(0..0).is_empty());
A RopeSliceMut
with characters should not be empty:
use an_rope::Rope; let mut an_rope = Rope::from("a string"); assert!(!an_rope.slice_mut(0..5).is_empty());
fn insert_rope<M>(&mut self, index: M, rope: Rope) where M: Metric,
Node: Measured<M>,
BranchNode: Measured<M>,
String: Measured<M>
Node: Measured<M>,
BranchNode: Measured<M>,
String: Measured<M>
Insert rope
into index
in this mutable RopeSlice
.
Note that the index to insert into is relative to the beginning of this
slice, not to the beginning of the sliced Rope
.
Consumes rope
.
Panics
- If
index
is greater than the length of thisRopeSlice
Time Complexity
O(log n)
Examples
If built with --features unstable
:
```
![feature(collections)]
![feature(collections_range)]
[cfg(feature = "unstable")]
extern crate collections; extern crate an_rope;
[cfg(feature = "unstable")]
fn main() {
use collections::range::RangeArgument; use an_rope::Rope;
let mut rope = Rope::from("this is a string");
{ // we have to create a new block here so that the mutable borrow
// on Rope
will end
let mut slice = rope.slice_mut(8..);
slice.insert_rope(1, Rope::from("n example"));
}
assert_eq!(&rope, "this is an example string");
}
fn insert(&mut self, index: usize, ch: char)
Insert ch
into index
in this mutable RopeSlice
.
Note that the index to insert into is relative to the beginning of this
slice, not to the beginning of the sliced Rope
.
Consumes ch
.
Panics
- If
index
is greater than the length of thisRopeSlice
Time Complexity
O(log n)
Examples
If built with --features unstable
:
```
![feature(collections)]
![feature(collections_range)]
[cfg(feature = "unstable")]
extern crate collections; extern crate an_rope;
[cfg(feature = "unstable")]
fn main() {
use collections::range::RangeArgument; use an_rope::Rope;
let mut rope = Rope::from("this is a string");
{ // we have to create a new block here so that the mutable borrow
// on Rope
will end
let mut slice = rope.slice_mut(8..);
slice.insert(1, 'n');
}
assert_eq!(&rope, "this is an string");
}
fn insert_str(&mut self, index: usize, s: &str)
Insert s
into index
in this mutable RopeSlice
.
Note that the index to insert into is relative to the beginning of this
slice, not to the beginning of the sliced Rope
.
Panics
- If
index
is greater than the length of thisRopeSlice
Time Complexity
O(log n)
Examples
If built with --features unstable
:
```
![feature(collections)]
![feature(collections_range)]
[cfg(feature = "unstable")]
extern crate collections; extern crate an_rope;
[cfg(feature = "unstable")]
fn main() {
use collections::range::RangeArgument; use an_rope::Rope;
let mut rope = Rope::from("this is a string");
{ // we have to create a new block here so that the mutable borrow
// on Rope
will end
let mut slice = rope.slice_mut(8..);
slice.insert_str(1, "n example");
}
assert_eq!(&rope, "this is an example string");
}
Trait Implementations
impl<'a> Debug for RopeSliceMut<'a>
[src]
impl<'a> Eq for RopeSliceMut<'a>
[src]
impl<'a> PartialEq for RopeSliceMut<'a>
[src]
fn eq(&self, other: &RopeSliceMut<'a>) -> bool
A rope equals another rope if all the bytes in both are equal.
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<'a, 'b> PartialEq<RopeSlice<'b>> for RopeSliceMut<'a>
[src]
fn eq(&self, other: &RopeSlice<'b>) -> bool
A rope equals another rope if all the bytes in both are equal.
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<'a> PartialEq<str> for RopeSliceMut<'a>
[src]
fn eq(&self, other: &str) -> bool
A rope equals another rope if all the bytes in both are equal.
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.