summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Oram <dev@mitmaro.ca>2022-02-04 23:41:38 -0330
committerTim Oram <dev@mitmaro.ca>2022-02-04 23:59:44 -0330
commit242fa155f4341ddd7407fcf3ad87f32636ce458c (patch)
treeb00c3b685acbcd69620e65825cc8bb63326d8fc7
parentb7a05ca36fd04356902b50b29b7cdc4a9c17a381 (diff)
Fix nightly and disabled lints in todo_file crate
-rw-r--r--src/todo_file/src/action.rs4
-rw-r--r--src/todo_file/src/edit_content.rs5
-rw-r--r--src/todo_file/src/history/mod.rs2
-rw-r--r--src/todo_file/src/lib.rs37
-rw-r--r--src/todo_file/src/line.rs19
-rw-r--r--src/todo_file/src/utils.rs4
6 files changed, 60 insertions, 11 deletions
diff --git a/src/todo_file/src/action.rs b/src/todo_file/src/action.rs
index 491871a..24475cb 100644
--- a/src/todo_file/src/action.rs
+++ b/src/todo_file/src/action.rs
@@ -33,6 +33,7 @@ pub enum Action {
impl Action {
/// Get the full string version of the action.
#[must_use]
+ #[inline]
pub fn as_string(self) -> String {
String::from(match self {
Self::Break => "break",
@@ -52,6 +53,7 @@ impl Action {
/// Get the abbreviated version of the action.
#[must_use]
+ #[inline]
pub fn to_abbreviation(self) -> String {
String::from(match self {
Self::Break => "b",
@@ -71,6 +73,7 @@ impl Action {
/// Can the action be changed.
#[must_use]
+ #[inline]
pub const fn is_static(self) -> bool {
match self {
Self::Break | Self::Exec | Self::Noop | Self::Reset | Self::Label | Self::Merge => true,
@@ -82,6 +85,7 @@ impl Action {
impl TryFrom<&str> for Action {
type Error = Error;
+ #[inline]
fn try_from(s: &str) -> Result<Self, Self::Error> {
match s {
"break" | "b" => Ok(Self::Break),
diff --git a/src/todo_file/src/edit_content.rs b/src/todo_file/src/edit_content.rs
index f7c34eb..270d03b 100644
--- a/src/todo_file/src/edit_content.rs
+++ b/src/todo_file/src/edit_content.rs
@@ -10,6 +10,7 @@ pub struct EditContext {
impl EditContext {
/// Create a new empty instance.
#[must_use]
+ #[inline]
pub const fn new() -> Self {
Self {
action: None,
@@ -19,6 +20,7 @@ impl EditContext {
/// Set the action.
#[must_use]
+ #[inline]
pub const fn action(mut self, action: Action) -> Self {
self.action = Some(action);
self
@@ -26,6 +28,7 @@ impl EditContext {
/// Set the content.
#[must_use]
+ #[inline]
pub fn content(mut self, content: &str) -> Self {
self.content = Some(content.to_owned());
self
@@ -33,12 +36,14 @@ impl EditContext {
/// Get the action.
#[must_use]
+ #[inline]
pub const fn get_action(&self) -> &Option<Action> {
&self.action
}
/// Get the content.
#[must_use]
+ #[inline]
pub const fn get_content(&self) -> &Option<String> {
&self.content
}
diff --git a/src/todo_file/src/history/mod.rs b/src/todo_file/src/history/mod.rs
index eeab4dd..68074b7 100644
--- a/src/todo_file/src/history/mod.rs
+++ b/src/todo_file/src/history/mod.rs
@@ -24,7 +24,7 @@ impl History {
Self {
redo_history: VecDeque::new(),
undo_history: VecDeque::new(),
- limit: limit as usize,
+ limit: limit.try_into().expect("History limit is too large"),
}
}
diff --git a/src/todo_file/src/lib.rs b/src/todo_file/src/lib.rs
index ef9ce26..dd6ddd4 100644
--- a/src/todo_file/src/lib.rs
+++ b/src/todo_file/src/lib.rs
@@ -68,14 +68,7 @@
rustdoc::private_intra_doc_links
)]
// LINT-REPLACE-END
-#![allow(
- clippy::as_conversions,
- clippy::indexing_slicing,
- clippy::integer_arithmetic,
- clippy::missing_errors_doc,
- clippy::missing_inline_in_public_items,
- clippy::module_name_repetitions
-)]
+#![allow(clippy::indexing_slicing, clippy::integer_arithmetic)]
//! Git Interactive Rebase Tool - Todo File Module
//!
@@ -117,6 +110,7 @@ pub struct TodoFile {
impl TodoFile {
/// Create a new instance.
#[must_use]
+ #[inline]
pub fn new(path: &str, undo_limit: u32, comment_char: &str) -> Self {
Self {
comment_char: String::from(comment_char),
@@ -129,6 +123,7 @@ impl TodoFile {
}
/// Set the rebase lines.
+ #[inline]
pub fn set_lines(&mut self, lines: Vec<Line>) {
self.is_noop = !lines.is_empty() && lines[0].get_action() == &Action::Noop;
self.lines = if self.is_noop {
@@ -144,6 +139,11 @@ impl TodoFile {
}
/// Load the rebase file from disk.
+ ///
+ /// # Errors
+ ///
+ /// Returns error if the file cannot be read.
+ #[inline]
pub fn load_file(&mut self) -> Result<()> {
let lines = read_to_string(Path::new(&self.filepath))
.map_err(|err| anyhow!("Error reading file: {}", self.filepath).context(err))?
@@ -162,6 +162,10 @@ impl TodoFile {
}
/// Write the rebase file to disk.
+ /// # Errors
+ ///
+ /// Returns error if the file cannot be written.
+ #[inline]
pub fn write_file(&self) -> Result<()> {
let mut file = File::create(&self.filepath)
.map_err(|err| anyhow!(err).context(anyhow!("Error opening file: {}", self.filepath)))?;
@@ -177,6 +181,7 @@ impl TodoFile {
}
/// Set the selected line index.
+ #[inline]
pub fn set_selected_line_index(&mut self, selected_line_index: usize) {
self.selected_line_index = if self.lines.is_empty() {
0
@@ -190,6 +195,7 @@ impl TodoFile {
}
/// Swap a range of lines up.
+ #[inline]
pub fn swap_range_up(&mut self, start_index: usize, end_index: usize) -> bool {
if end_index == 0 || start_index == 0 || self.lines.is_empty() {
return false;
@@ -210,6 +216,7 @@ impl TodoFile {
}
/// Swap a range of lines down.
+ #[inline]
pub fn swap_range_down(&mut self, start_index: usize, end_index: usize) -> bool {
let len = self.lines.len();
let max_index = if len == 0 { 0 } else { len - 1 };
@@ -224,6 +231,7 @@ impl TodoFile {
}
/// Add a new line.
+ #[inline]
pub fn add_line(&mut self, index: usize, line: Line) {
let i = if index > self.lines.len() {
self.lines.len()
@@ -236,6 +244,7 @@ impl TodoFile {
}
/// Remove a range of lines.
+ #[inline]
pub fn remove_lines(&mut self, start_index: usize, end_index: usize) {
if self.lines.is_empty() {
return;
@@ -255,6 +264,7 @@ impl TodoFile {
}
/// Update a range of lines.
+ #[inline]
pub fn update_range(&mut self, start_index: usize, end_index: usize, edit_context: &EditContext) {
if self.lines.is_empty() {
return;
@@ -287,23 +297,27 @@ impl TodoFile {
}
/// Undo the last modification.
+ #[inline]
pub fn undo(&mut self) -> Option<(usize, usize)> {
self.history.undo(&mut self.lines)
}
/// Redo the last undone modification.
+ #[inline]
pub fn redo(&mut self) -> Option<(usize, usize)> {
self.history.redo(&mut self.lines)
}
/// Get the selected line.
#[must_use]
+ #[inline]
pub fn get_selected_line(&self) -> Option<&Line> {
self.lines.get(self.selected_line_index)
}
/// Get the index of the last line that can be selected.
#[must_use]
+ #[inline]
pub fn get_max_selected_line_index(&self) -> usize {
let len = self.lines.len();
if len == 0 {
@@ -316,42 +330,49 @@ impl TodoFile {
/// Get the selected line index
#[must_use]
+ #[inline]
pub const fn get_selected_line_index(&self) -> usize {
self.selected_line_index
}
/// Get the file path to the rebase file.
#[must_use]
+ #[inline]
pub fn get_filepath(&self) -> &str {
self.filepath.as_str()
}
/// Get a line by index.
#[must_use]
+ #[inline]
pub fn get_line(&self, index: usize) -> Option<&Line> {
self.lines.get(index)
}
/// Get an owned copy of the lines.
#[must_use]
+ #[inline]
pub fn get_lines_owned(&self) -> Vec<Line> {
self.lines.clone()
}
/// Is the rebase file a noop.
#[must_use]
+ #[inline]
pub const fn is_noop(&self) -> bool {
self.is_noop
}
/// Get an iterator over the lines.
#[must_use]
+ #[inline]
pub fn lines_iter(&self) -> Iter<'_, Line> {
self.lines.iter()
}
/// Does the rebase file contain no lines.
#[must_use]
+ #[inline]
pub fn is_empty(&self) -> bool {
self.lines.is_empty()
}
diff --git a/src/todo_file/src/line.rs b/src/todo_file/src/line.rs
index 6b92953..947a8a0 100644
--- a/src/todo_file/src/line.rs
+++ b/src/todo_file/src/line.rs
@@ -25,6 +25,7 @@ impl Line {
/// Create a new pick line.
#[must_use]
+ #[inline]
pub fn new_pick(hash: &str) -> Self {
Self {
action: Action::Pick,
@@ -36,6 +37,7 @@ impl Line {
/// Create a new break line.
#[must_use]
+ #[inline]
pub fn new_break() -> Self {
Self {
action: Action::Break,
@@ -47,6 +49,7 @@ impl Line {
/// Create a new exec line.
#[must_use]
+ #[inline]
pub fn new_exec(command: &str) -> Self {
Self {
action: Action::Exec,
@@ -58,6 +61,7 @@ impl Line {
/// Create a new merge line.
#[must_use]
+ #[inline]
pub fn new_merge(command: &str) -> Self {
Self {
action: Action::Merge,
@@ -69,6 +73,7 @@ impl Line {
/// Create a new label line.
#[must_use]
+ #[inline]
pub fn new_label(label: &str) -> Self {
Self {
action: Action::Label,
@@ -80,6 +85,7 @@ impl Line {
/// Create a new reset line.
#[must_use]
+ #[inline]
pub fn new_reset(label: &str) -> Self {
Self {
action: Action::Reset,
@@ -90,6 +96,11 @@ impl Line {
}
/// Create a new line from a rebase file line.
+ ///
+ /// # Errors
+ ///
+ /// Returns an error if an invalid line is provided.
+ #[inline]
pub fn new(input_line: &str) -> Result<Self> {
if input_line.starts_with("noop") {
return Ok(Self::new_noop());
@@ -137,6 +148,7 @@ impl Line {
}
/// Set the action of the line.
+ #[inline]
pub fn set_action(&mut self, action: Action) {
if !self.action.is_static() && self.action != action {
self.mutated = true;
@@ -145,6 +157,7 @@ impl Line {
}
/// Edit the content of the line, if it is editable.
+ #[inline]
pub fn edit_content(&mut self, content: &str) {
if self.is_editable() {
self.content = String::from(content);
@@ -153,30 +166,35 @@ impl Line {
/// Get the action of the line.
#[must_use]
+ #[inline]
pub const fn get_action(&self) -> &Action {
&self.action
}
/// Get the content of the line.
#[must_use]
+ #[inline]
pub fn get_content(&self) -> &str {
self.content.as_str()
}
/// Get the commit hash for the line.
#[must_use]
+ #[inline]
pub fn get_hash(&self) -> &str {
self.hash.as_str()
}
/// Does this line contain a commit reference.
#[must_use]
+ #[inline]
pub fn has_reference(&self) -> bool {
!self.hash.is_empty()
}
/// Can this line be edited.
#[must_use]
+ #[inline]
pub const fn is_editable(&self) -> bool {
match self.action {
Action::Exec | Action::Label | Action::Reset | Action::Merge => true,
@@ -193,6 +211,7 @@ impl Line {
/// Create a string containing a textual version of the line, as would be seen in the rebase file.
#[must_use]
+ #[inline]
pub fn to_text(&self) -> String {
match self.action {
Action::Drop | Action::Edit | Action::Fixup | Action::Pick | Action::Reword | Action::Squash => {
diff --git a/src/todo_file/src/utils.rs b/src/todo_file/src/utils.rs
index 2b5619f..896d07d 100644
--- a/src/todo_file/src/utils.rs
+++ b/src/todo_file/src/utils.rs
@@ -1,6 +1,6 @@
use super::line::Line;
-pub(crate) fn swap_range_up(lines: &mut Vec<Line>, start_index: usize, end_index: usize) {
+pub(crate) fn swap_range_up(lines: &mut [Line], start_index: usize, end_index: usize) {
let range = if end_index <= start_index {
(end_index - 1)..start_index
}
@@ -12,7 +12,7 @@ pub(crate) fn swap_range_up(lines: &mut Vec<Line>, start_index: usize, end_index
}
}
-pub(crate) fn swap_range_down(lines: &mut Vec<Line>, start_index: usize, end_index: usize) {
+pub(crate) fn swap_range_down(lines: &mut [Line], start_index: usize, end_index: usize) {
let range = if end_index <= start_index {
end_index..=start_index
}