Skip to content

Commit

Permalink
Rewrite without unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
YS-L committed Jan 1, 2024
1 parent b670c8b commit 75a4fe0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::util::events::{CsvlensEvent, CsvlensEvents};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use std::collections::hash_map::Entry::Vacant;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::HashMap;
use tui_input::backend::crossterm::EventHandler;
use tui_input::Input;
Expand Down Expand Up @@ -121,12 +121,13 @@ impl BufferHistoryContainer {
}

fn set(&mut self, input_mode: InputMode, content: &str) {
if let Vacant(e) = self.inner.entry(input_mode) {
e.insert(BufferHistory::new_with(content));
} else {
// TODO: rewrite without unwrap?
let history = self.inner.get_mut(&input_mode).unwrap();
history.push(content);
match self.inner.entry(input_mode) {
Occupied(mut e) => {
e.get_mut().push(content);
}
Vacant(e) => {
e.insert(BufferHistory::new_with(content));
}
}
}

Expand Down

0 comments on commit 75a4fe0

Please sign in to comment.