GapBuffer

Struct GapBuffer 

Source
pub struct GapBuffer { /* private fields */ }
Expand description

Most people know how Vec<T> works: It has some spare capacity at the end, so that pushing into it doesn’t reallocate every single time. A gap buffer is the same thing, but the spare capacity can be anywhere in the buffer. This variant is optimized for large buffers and uses virtual memory.

Implementations§

Source§

impl GapBuffer

Source

pub fn new(small: bool) -> Result<Self>

Source

pub fn len(&self) -> usize

Source

pub fn generation(&self) -> u32

Source

pub fn set_generation(&mut self, generation: u32)

Source

pub fn allocate_gap( &mut self, off: usize, len: usize, delete: usize, ) -> &mut [u8]

WARNING: The returned slice must not necessarily be the same length as len (due to OOM).

Source

pub fn commit_gap(&mut self, len: usize)

Source

pub fn replace(&mut self, range: Range<usize>, src: &[u8])

Source

pub fn clear(&mut self)

Source

pub fn extract_raw( &self, range: Range<usize>, out: &mut Vec<u8>, out_off: usize, )

Source

pub fn copy_from(&mut self, src: &dyn ReadableDocument) -> bool

Replaces the entire buffer contents with the given text. The method is optimized for the case where the given text already matches the existing contents. Returns true if the buffer contents were changed.

Source

pub fn copy_into(&self, dst: &mut dyn WriteableDocument)

Copies the contents of the buffer into a string.

Trait Implementations§

Source§

impl ReadableDocument for GapBuffer

Source§

fn read_forward(&self, off: usize) -> &[u8]

Read some bytes starting at (including) the given absolute offset. Read more
Source§

fn read_backward(&self, off: usize) -> &[u8]

Read some bytes before (but not including) the given absolute offset. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.