Struct ropey::RopeBuilder
[−]
[src]
pub struct RopeBuilder { /* fields omitted */ }
An incremental Rope
builder.
RopeBuilder
is used to efficiently build Rope
s from sequences
of text chunks. It is useful for situations such as:
- Creating a rope from a large text file without pre-loading the
entire contents of the file into memory (but see
Rope::from_reader()
which usesRopeBuilder
internally for precisely this use-case). - Creating a rope from a streaming data source.
- Loading a non-utf8 text source into a rope, doing the encoding conversion incrementally as you go.
Unlike repeatedly calling Rope::insert()
on the end of a rope,
this API runs in time linear to the amount of data fed to it, and
is overall much faster. It also creates more memory-compact ropes.
(The converse of this API is the Chunks
iterator.)
Example
let mut builder = RopeBuilder::new(); builder.append("Hello "); builder.append("world!\n"); builder.append("How's "); builder.append("it goin"); builder.append("g?"); let rope = builder.finish(); assert_eq!(rope, "Hello world!\nHow's it going?");
Methods
impl RopeBuilder
[src]
fn new() -> RopeBuilder
[src]
Creates a new RopeBuilder, ready for input.
fn append(&mut self, chunk: &str)
[src]
Appends chunk
to the end of the in-progress Rope
.
This method is called repeatedly to incrementally build up a
Rope
. The passed text chunk can be as large or small as
desired, but larger chunks are more efficient.
chunk
must be valid utf8 text.
fn finish(self) -> Rope
[src]
Finishes the build, and returns the Rope
.
Note: this method consumes the builder. If you want to continue
building other ropes with the same prefix, you can clone the builder
before calling finish()
.
Trait Implementations
impl Debug for RopeBuilder
[src]
impl Clone for RopeBuilder
[src]
fn clone(&self) -> RopeBuilder
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more