From 869cb187b64f15c64eadef8eb7e70d6d61a0cc51 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sun, 15 Mar 2015 16:03:23 -0700 Subject: [PATCH] Migrated code from std::old_io to std::io --- src/buffer/mod.rs | 24 +++++++++++++----------- src/editor/mod.rs | 10 +++++----- src/main.rs | 4 +--- src/term_ui/mod.rs | 5 ++--- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index bd84c8c..e1080a5 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -2,9 +2,10 @@ use std::mem; use std::cmp::min; -use std::old_path::Path; -use std::old_io::fs::File; -use std::old_io::{IoResult, BufferedReader, BufferedWriter}; +use std::path::{Path, PathBuf}; +use std::fs::File; +use std::io; +use std::io::{BufReader, BufWriter, Read, Write}; use ropey::{Rope, RopeSlice, RopeGraphemeIter, RopeLineIter}; use self::undo_stack::{UndoStack}; @@ -21,7 +22,7 @@ mod undo_stack; /// A text buffer pub struct Buffer { text: Rope, - file_path: Option, + file_path: Option, undo_stack: UndoStack, } @@ -46,13 +47,14 @@ impl Buffer { } - pub fn new_from_file(path: &Path) -> IoResult { - let mut f = BufferedReader::new(try!(File::open(path))); - let string = f.read_to_string().unwrap(); + pub fn new_from_file(path: &Path) -> io::Result { + let mut f = BufReader::new(try!(File::open(path))); + let mut string = String::new(); + try!(f.read_to_string(&mut string)); let buf = Buffer { text: Rope::from_str(string.as_slice()), - file_path: Some(path.clone()), + file_path: Some(path.to_path_buf()), undo_stack: UndoStack::new(), }; @@ -60,11 +62,11 @@ impl Buffer { } - pub fn save_to_file(&self, path: &Path) -> IoResult<()> { - let mut f = BufferedWriter::new(try!(File::create(path))); + pub fn save_to_file(&self, path: &Path) -> io::Result<()> { + let mut f = BufWriter::new(try!(File::create(path))); for c in self.text.chunk_iter() { - let _ = f.write_str(c); + let _ = f.write(c.as_bytes()); } return Ok(()); diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 1004a80..1bd6639 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -3,7 +3,7 @@ use buffer::Buffer; use formatter::LineFormatter; use formatter::RoundingBehavior::*; -use std::old_path::Path; +use std::path::{Path, PathBuf}; use std::cmp::{min, max}; use string_utils::{grapheme_count, str_to_line_ending, LineEnding}; use utils::digit_count; @@ -15,7 +15,7 @@ mod cursor; pub struct Editor { pub buffer: Buffer, pub formatter: T, - pub file_path: Path, + pub file_path: PathBuf, pub line_ending_type: LineEnding, pub soft_tabs: bool, pub soft_tab_width: u8, @@ -40,7 +40,7 @@ impl Editor { Editor { buffer: Buffer::new(), formatter: formatter, - file_path: Path::new(""), + file_path: PathBuf::new(""), line_ending_type: LineEnding::LF, soft_tabs: false, soft_tab_width: 4, @@ -63,7 +63,7 @@ impl Editor { let mut ed = Editor { buffer: buf, formatter: formatter, - file_path: path.clone(), + file_path: path.to_path_buf(), line_ending_type: LineEnding::LF, soft_tabs: false, soft_tab_width: 4, @@ -89,7 +89,7 @@ impl Editor { pub fn save_if_dirty(&mut self) { - if self.dirty && self.file_path != Path::new("") { + if self.dirty && self.file_path != PathBuf::new("") { let _ = self.buffer.save_to_file(&self.file_path); self.dirty = false; } diff --git a/src/main.rs b/src/main.rs index 5b8b2f5..b334df5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ #![feature(core)] -#![feature(old_io)] #![feature(collections)] -#![feature(old_path)] #![feature(test)] #![feature(std_misc)] @@ -14,7 +12,7 @@ extern crate ropey; //extern crate freetype; //extern crate sdl2; -use std::old_path::Path; +use std::path::Path; use docopt::Docopt; use editor::Editor; use term_ui::TermUI; diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index 35e7701..d9ebb7d 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -5,7 +5,6 @@ use rustbox::Color; use editor::Editor; use formatter::{LineFormatter, LINE_BLOCK_LENGTH, block_index_and_offset}; use std::char; -use std::old_io::stdio; use std::default::Default; use std::time::duration::Duration; use std::cmp::min; @@ -47,7 +46,7 @@ pub struct TermUI { impl TermUI { pub fn new() -> TermUI { let rb = match rustbox::RustBox::init(rustbox::InitOptions { - buffer_stderr: stdio::stderr_raw().isatty(), + buffer_stderr: false, ..Default::default() }) { Ok(rbox) => rbox, @@ -68,7 +67,7 @@ impl TermUI { pub fn new_from_editor(ed: Editor) -> TermUI { let rb = match rustbox::RustBox::init(rustbox::InitOptions { - buffer_stderr: stdio::stderr_raw().isatty(), + buffer_stderr: false, ..Default::default() }) { Ok(rbox) => rbox,