Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing unused errors and unwraps #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Context {
pub fn read_line<P: Into<String>>(
&mut self,
prompt: P,
mut handler: &mut EventHandler<RawTerminal<Stdout>>,
handler: &mut EventHandler<RawTerminal<Stdout>>,
) -> io::Result<String> {
self.read_line_with_init_buffer(prompt, handler, Buffer::new())
}
Expand All @@ -88,12 +88,12 @@ impl Context {
pub fn read_line_with_init_buffer<P: Into<String>, B: Into<Buffer>>(
&mut self,
prompt: P,
mut handler: &mut EventHandler<RawTerminal<Stdout>>,
handler: &mut EventHandler<RawTerminal<Stdout>>,
buffer: B,
) -> io::Result<String> {
let res = {
let stdout = stdout().into_raw_mode().unwrap();
let ed = try!(Editor::new_with_init_buffer(stdout, prompt, self, buffer));
let stdout = stdout().into_raw_mode()?;
let ed = Editor::new_with_init_buffer(stdout, prompt, self, buffer)?;
match self.key_bindings {
KeyBindings::Emacs => Self::handle_keys(keymap::Emacs::new(ed), handler),
KeyBindings::Vi => Self::handle_keys(keymap::Vi::new(ed), handler),
Expand All @@ -106,7 +106,7 @@ impl Context {

fn handle_keys<'a, T, W: Write, M: KeyMap<'a, W, T>>(
mut keymap: M,
mut handler: &mut EventHandler<W>,
handler: &mut EventHandler<W>,
) -> io::Result<String>
where
String: From<M>,
Expand Down
2 changes: 1 addition & 1 deletion src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl<'a, W: Write> Editor<'a, W> {
if self.show_autosuggestions {
{
let autosuggestion = self.current_autosuggestion().cloned();
let mut buf = self.current_buffer_mut();
let buf = self.current_buffer_mut();
if let Some(x) = autosuggestion {
buf.insert_from_buffer(&x);
}
Expand Down
15 changes: 6 additions & 9 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ fn write_to_disk(max_file_size: usize, new_item: &Buffer, file_name: &str) -> io
.create(true)
.open(file_name)?;

// The metadata contains the length of the file
let file_length = file.metadata().ok().map_or(0u64, |m| m.len());

{
// Count number of entries in file
let mut num_stored = 0;
Expand Down Expand Up @@ -277,7 +274,7 @@ fn write_to_disk(max_file_size: usize, new_item: &Buffer, file_name: &str) -> io


// Move it all back
move_file_contents_backward(&mut file, move_dist);
move_file_contents_backward(&mut file, move_dist)?;
}
};

Expand All @@ -294,10 +291,10 @@ fn write_to_disk(max_file_size: usize, new_item: &Buffer, file_name: &str) -> io

fn move_file_contents_backward(file: &mut File, distance: u64) -> io::Result<()> {
let mut total_read = 0;
let mut buffer = [0u8, 4096];
let mut buffer = [0u8; 4096];

file.seek(SeekFrom::Start(distance))?;

loop {
// Read 4K of bytes all at once into the buffer.
let read = file.read(&mut buffer)?;
Expand All @@ -307,15 +304,15 @@ fn move_file_contents_backward(file: &mut File, distance: u64) -> io::Result<()>
break;
}

file.seek(SeekFrom::Current(-(read as i64 + distance as i64)));
file.seek(SeekFrom::Current(-(read as i64 + distance as i64)))?;


file.write_all(&buffer[..read])?;
file.seek(SeekFrom::Current(distance as i64));
file.seek(SeekFrom::Current(distance as i64))?;
}

file.set_len(total_read)?;
file.flush()?;

Ok(())
}
}