index : yed
VimLike Text Editor in Rust
about summary refs log tree commit diff

Diffstat (limited to 'src/buffer.rs')

-rw-r--r-- src/buffer.rs 15
 1 file changed, 15 insertions(+)

diff --git a/src/buffer.rs b/src/buffer.rs
new file mode 100644
index 0000000..ec4311a 100644
--- /dev/null
+++ b/src/buffer.rs
@@ -1,0 +1,15 @@
pub struct Buffer {
    pub file: Option<String>,
    pub lines: Vec<String>
}

impl Buffer {
    pub fn from_file(file: Option<String>) -> Self {
        let lines = match &file {
            Some(file) => std::fs::read_to_string(file).unwrap().lines().map(|s| s.to_string()).collect(),
            None => vec![],
        };

        Self { file, lines }
    }
}