Module an_rope::metric
[−]
[src]
Metrics for indexing Rope
s.
A Metric
represents a measurement with which indices into a Rope
may be calculated.
All Rope
methods are optionally parameterised with Metric
s. This
means that you can split
, insert
, or delete
Ropes on character,
line, or grapheme indices, without necessitating the addition of a whole
bunch of new, wordy method names like split_on_grapheme_index
and so on.
Examples
If I wanted to delete characters 10 to 15 from rope r, I could say:
let r = Rope::from("this is a long rope"); let r = r.delete(10..15); assert_eq!(&r, "this is a rope");
Suppose my Rope
contained some strange Unicode characters, and I realised
that I actually wanted to delete graphemes 10 to 13. In that case, I
could say:
use an_rope::metric::Grapheme; let r = Rope::from("this is a 🆒🆕 rope, 🆗!"); let r = r.delete(Grapheme(10)..Grapheme(13)); assert_eq!(&r, "this is a rope, 🆗!");
Or, suppose my Rope
spanned multiple lines:
use an_rope::metric::Line; let r = Rope::from("this is\n\ a\n\ multi\n\ line\n\ rope"); let r = r.delete(Line(2)..Line(3)); assert_eq!(&r, "this is\na\nrope");
Structs
Grapheme |
A metric for calculating indices in |
Line |
A metric for calculating indices in |
Traits
Measured |
Trait indicating that a type may be measured with |
Metric |
A monoid that can be applied to a type as a measurement. |
Monoid |
The class of monoids |