Struct scribe::buffer::GapBuffer[][src]

pub struct GapBuffer { /* fields omitted */ }

A UTF-8 string buffer designed to minimize reallocations, maintaining performance amid frequent modifications.

Methods

impl GapBuffer
[src]

Initializes a gap buffer with the specified data as its contents.

Examples

use scribe::buffer::GapBuffer;

let buffer = GapBuffer::new("scribe".to_string());
assert_eq!(buffer.to_string(), "scribe");

Inserts the specified data into the buffer at the specified position. The buffer will reallocate if there is insufficient space. If the position is out of bounds, the buffer contents will remain unchanged.

Examples

use scribe::buffer::GapBuffer;

let mut buffer = GapBuffer::new("my buffer data".to_string());
buffer.insert(" changed", &scribe::buffer::Position{ line: 0, offset: 2});
assert_eq!("my changed buffer data", buffer.to_string());

Returns the specified range of data from the buffer. If any part of the range does not exist, a none value will be returned.

Examples

use scribe::buffer::{GapBuffer, Range};

let buffer = GapBuffer::new("my data".to_string());
let range = Range::new(
  scribe::buffer::Position{ line: 0, offset: 3 },
  scribe::buffer::Position{ line: 0, offset: 7}
);

assert_eq!(buffer.read(&range).unwrap(), "data");

Returns a string representation of the buffer data (without gap).

Examples

use scribe::buffer::GapBuffer;

let mut buffer = GapBuffer::new("my data".to_string());
assert_eq!(buffer.to_string(), "my data");

Removes the specified range of data from the buffer.

Examples

use scribe::buffer::{GapBuffer, Range};

let mut buffer = GapBuffer::new("my data".to_string());
let range = Range::new(
  scribe::buffer::Position{ line: 0, offset: 0 },
  scribe::buffer::Position{ line: 0, offset: 3}
);

buffer.delete(&range);
assert_eq!(buffer.to_string(), "data");

Checks whether or not the specified position is in bounds of the buffer data.

Examples

use scribe::buffer::GapBuffer;

let buffer = GapBuffer::new("scribe".to_string());
let in_bounds = scribe::buffer::Position{ line: 0, offset: 0 };
let out_of_bounds = scribe::buffer::Position{ line: 1, offset: 3 };

assert_eq!(buffer.in_bounds(&in_bounds), true);
assert_eq!(buffer.in_bounds(&out_of_bounds), false);

Auto Trait Implementations

impl Send for GapBuffer

impl Sync for GapBuffer