Skip to content

Commit

Permalink
Refactor Buffer::from_file to use read_to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Feb 13, 2024
1 parent 7cda56a commit ef63a9b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::cell::RefCell;
use std::default::Default;
use std::fs::{self, File};
use std::io;
use std::io::{Read, Write};
use std::io::Write;
use std::ops::Fn;
use std::path::{Path, PathBuf};
use std::rc::Rc;
Expand Down Expand Up @@ -114,11 +114,9 @@ impl Buffer {
/// ```
pub fn from_file(path: &Path) -> io::Result<Buffer> {
// Try to open and read the file, returning any errors encountered.
let mut file = File::open(path)?;
let mut data = String::new();
file.read_to_string(&mut data)?;
let content = fs::read_to_string(path)?;

let data = Rc::new(RefCell::new(GapBuffer::new(data)));
let data = Rc::new(RefCell::new(GapBuffer::new(content)));
let cursor = Cursor::new(data.clone(), Position { line: 0, offset: 0 });

// Create a new buffer using the loaded data, path, and other defaults.
Expand Down

0 comments on commit ef63a9b

Please sign in to comment.