Closed hawkw closed 7 years ago
Of course, Rope slices aren't done, they don't implement all of the methods we'd eventually like them to, but the same is true of Rope
, and a majority of these methods on RopeSlice
are waiting until the same methods are implemented for Rope
s.
@cjm00, when you've got a spare minute, I'd love it if you'd glance over this before I go ahead and merge it.
@cjm00, since you're currently without internet access, I'm gonna go ahead and merge this.
This PR implements
Rope
slicing. We use a customRopeSlice
type to represent slices of a Rope, rather than constructing an&str
, so that you can slice a rope cheaply, and slice a rope mutably but still modify the underlyingRope
.RopeSlice
s may beconvert
ed into newRope
s or intoString
s. MutableRopeSlice
s expose the same set ofinsert_*
methods asRope
s, which mutate the slicedRope
in place.I'd like for
Rope
to implementBorrow<RopeSlice<'a>>
, so that we can returnRopeSlice
s fromops::Index
, but due to limitations in Rust's type system, this is currently not possible. Currently,RopeSlice
s are produced using theRope.slice()
method, which is slightly less ergonomic, but allows us to return a non-reference type as the borrowed form.Rope.slice()
takes aRangeArgument<usize>
, so it can be called with range syntax like..
,a..
,..b
orc..d
.This PR also includes an implementation for
Rope::char_indices()
. Closes #26.Closes #19.