From 6823706d692848a5a7c5fdf10fb6ff57056e0581 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 6 Jul 2015 18:39:00 -0700 Subject: [PATCH] Working towards rust stable support. --- Cargo.toml | 1 + src/buffer/mod.rs | 2 +- src/editor/cursor.rs | 10 +++++----- src/editor/mod.rs | 4 ++-- src/formatter.rs | 2 +- src/main.rs | 1 + src/string_utils.rs | 10 +++++----- src/term_ui/mod.rs | 4 ++-- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 28f285b..904a8a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ git = "https://github.com/cessen/ropey.git" #git = "https://github.com/PistonDevelopers/freetype-rs.git" [dependencies] +time = "0.1.30" rustc-serialize = "0.3.0" docopt = "0.6.*" encoding = "*" diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index e1080a5..d9aa5e2 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -53,7 +53,7 @@ impl Buffer { try!(f.read_to_string(&mut string)); let buf = Buffer { - text: Rope::from_str(string.as_slice()), + text: Rope::from_str(&string[..]), file_path: Some(path.to_path_buf()), undo_stack: UndoStack::new(), }; diff --git a/src/editor/cursor.rs b/src/editor/cursor.rs index ab02e70..500e75d 100644 --- a/src/editor/cursor.rs +++ b/src/editor/cursor.rs @@ -13,7 +13,7 @@ use formatter::LineFormatter; /// /// `vis_start` is the visual 2d horizontal position of the cursor. This /// doesn't affect editing operations at all, but is used for cursor movement. -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct Cursor { pub range: (usize, usize), // start, end pub vis_start: usize, // start @@ -96,14 +96,14 @@ impl CursorSet { impl Index for CursorSet { type Output = Cursor; - fn index<'a>(&'a self, _index: &usize) -> &'a Cursor { - &(self.cursors[*_index]) + fn index<'a>(&'a self, _index: usize) -> &'a Cursor { + &(self.cursors[_index]) } } impl IndexMut for CursorSet { - fn index_mut<'a>(&'a mut self, _index: &usize) -> &'a mut Cursor { - &mut (self.cursors[*_index]) + fn index_mut<'a>(&'a mut self, _index: usize) -> &'a mut Cursor { + &mut (self.cursors[_index]) } } \ No newline at end of file diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 1bd6639..76256f3 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -40,7 +40,7 @@ impl Editor { Editor { buffer: Buffer::new(), formatter: formatter, - file_path: PathBuf::new(""), + file_path: PathBuf::new(), 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 != PathBuf::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/formatter.rs b/src/formatter.rs index cd417d9..fd142e0 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -10,7 +10,7 @@ use buffer::Buffer; pub const LINE_BLOCK_LENGTH: usize = 4096; -#[derive(Copy, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub enum RoundingBehavior { Round, Floor, diff --git a/src/main.rs b/src/main.rs index 8ee62cd..7651c3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ #![feature(test)] #![feature(std_misc)] +extern crate time; extern crate test; extern crate rustbox; extern crate docopt; diff --git a/src/string_utils.rs b/src/string_utils.rs index 0613ec0..c1d9b94 100644 --- a/src/string_utils.rs +++ b/src/string_utils.rs @@ -140,7 +140,7 @@ pub fn grapheme_pos_to_byte_pos(text: &str, pos: usize) -> usize { /// Inserts the given text into the given string at the given grapheme index. pub fn insert_text_at_grapheme_index(s: &mut String, text: &str, pos: usize) { // Find insertion position in bytes - let byte_pos = grapheme_pos_to_byte_pos(s.as_slice(), pos); + let byte_pos = grapheme_pos_to_byte_pos(&s[..], pos); // Get byte vec of string let byte_vec = unsafe { s.as_mut_vec() }; @@ -182,8 +182,8 @@ pub fn remove_text_between_grapheme_indices(s: &mut String, pos_a: usize, pos_b: // Find removal positions in bytes // TODO: get both of these in a single pass - let byte_pos_a = grapheme_pos_to_byte_pos(s.as_slice(), pos_a); - let byte_pos_b = grapheme_pos_to_byte_pos(s.as_slice(), pos_b); + let byte_pos_a = grapheme_pos_to_byte_pos(&s[..], pos_a); + let byte_pos_b = grapheme_pos_to_byte_pos(&s[..], pos_b); // Get byte vec of string let byte_vec = unsafe { s.as_mut_vec() }; @@ -211,7 +211,7 @@ pub fn split_string_at_grapheme_index(s1: &mut String, pos: usize) -> String { // Code block to contain the borrow of s2 { - let byte_pos = grapheme_pos_to_byte_pos(s1.as_slice(), pos); + let byte_pos = grapheme_pos_to_byte_pos(&s1[..], pos); let byte_vec_1 = unsafe { s1.as_mut_vec() }; let byte_vec_2 = unsafe { s2.as_mut_vec() }; @@ -231,7 +231,7 @@ pub fn split_string_at_grapheme_index(s1: &mut String, pos: usize) -> String { /// Represents one of the valid Unicode line endings. /// Also acts as an index into `LINE_ENDINGS`. -#[derive(PartialEq, Copy)] +#[derive(PartialEq, Copy, Clone)] pub enum LineEnding { None = 0, // No line ending CRLF = 1, // CarriageReturn followed by LineFeed diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index d9ebb7d..bcc0d75 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -3,10 +3,10 @@ use rustbox; use rustbox::Color; use editor::Editor; +use time::Duration; use formatter::{LineFormatter, LINE_BLOCK_LENGTH, block_index_and_offset}; use std::char; use std::default::Default; -use std::time::duration::Duration; use std::cmp::min; use string_utils::{is_line_ending, line_ending_to_str, LineEnding}; use utils::digit_count; @@ -387,7 +387,7 @@ impl TermUI { let lnx = c1.1 + (gutter_width - 1 - digit_count(line_num as u32, 10) as usize); let lny = screen_line as usize; if lny >= c1.0 && lny <= c2.0 { - self.rb.print(lnx, lny, rustbox::RB_NORMAL, Color::White, Color::Blue, format!("{}", line_num).as_slice()); + self.rb.print(lnx, lny, rustbox::RB_NORMAL, Color::White, Color::Blue, &format!("{}", line_num)[..]); } }