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