Struct ropey::RopeBuilder

source ·
pub struct RopeBuilder { /* private fields */ }
Expand description

An efficient incremental Rope builder.

This is used to efficiently build ropes from sequences of text chunks. It is useful for creating ropes from:

  • …large text files, without pre-loading their entire contents into memory (but see from_reader() for a convenience function that does this for casual use-cases).
  • …streaming data sources.
  • …non-utf8 text data, 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.

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?");

Implementations§

source§

impl RopeBuilder

source

pub fn new() -> Self

Creates a new RopeBuilder, ready for input.

source

pub fn append(&mut self, chunk: &str)

Appends chunk to the end of the in-progress Rope.

Call this method 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.

source

pub fn finish(self) -> Rope

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§

source§

impl Clone for RopeBuilder

source§

fn clone(&self) -> RopeBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RopeBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for RopeBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.