Add some documentation
This commit is contained in:
parent
00e4959055
commit
1de9569beb
|
|
@ -1,2 +1,2 @@
|
|||
mod text_buffer;
|
||||
pub use text_buffer::{TextBuffer, TextBufferReader, TextBufferWriter};
|
||||
pub use text_buffer::{Point, TextBuffer, TextBufferReader, TextBufferWriter};
|
||||
|
|
|
|||
|
|
@ -10,29 +10,36 @@ pub use reader::TextBufferReader;
|
|||
mod writer;
|
||||
pub use writer::TextBufferWriter;
|
||||
|
||||
/// A block of text, usually containing the contents of a text file.
|
||||
pub struct TextBuffer {
|
||||
contents: Rc<Rope>,
|
||||
}
|
||||
|
||||
/// A location in a [TextBuffer]
|
||||
pub enum Point {
|
||||
/// The end of the buffer
|
||||
End,
|
||||
}
|
||||
|
||||
impl TextBuffer {
|
||||
/// Create a new empty [TextBuffer]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
contents: Rope::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The size of the contents in bytes
|
||||
pub fn num_bytes(&self) -> usize {
|
||||
self.contents.total_bytes()
|
||||
}
|
||||
|
||||
/// The size of the contents in characters
|
||||
pub fn num_chars(&self) -> usize {
|
||||
self.contents.total_chars()
|
||||
}
|
||||
|
||||
/// The total number of lines in the contents
|
||||
pub fn num_lines(&self) -> usize {
|
||||
let num_chars = self.num_chars();
|
||||
if num_chars == 0 {
|
||||
|
|
@ -51,6 +58,7 @@ impl TextBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Insert `text` at `point`.
|
||||
pub fn insert_text(&mut self, text: impl Into<String>, point: Point) {
|
||||
match point {
|
||||
Point::End => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue