diff --git a/src/core_editor/editor.rs b/src/core_editor/editor.rs index 59d645b..b837d1b 100644 --- a/src/core_editor/editor.rs +++ b/src/core_editor/editor.rs @@ -27,7 +27,7 @@ impl Default for Editor { impl Editor { /// Get the current [`LineBuffer`] - pub fn line_buffer(&self) -> &LineBuffer { + pub const fn line_buffer(&self) -> &LineBuffer { &self.line_buffer } diff --git a/src/edit_mode/emacs.rs b/src/edit_mode/emacs.rs index fc3b0bf..b8cbf92 100644 --- a/src/edit_mode/emacs.rs +++ b/src/edit_mode/emacs.rs @@ -162,7 +162,7 @@ impl EditMode for Emacs { impl Emacs { /// Emacs style input parsing constructor if you want to use custom keybindings - pub fn new(keybindings: Keybindings) -> Self { + pub const fn new(keybindings: Keybindings) -> Self { Emacs { keybindings } } } diff --git a/src/history/base.rs b/src/history/base.rs index 16b8b49..798d321 100644 --- a/src/history/base.rs +++ b/src/history/base.rs @@ -54,6 +54,7 @@ pub struct SearchFilter { /// Filter whether the command completed pub exit_successful: Option, } + impl SearchFilter { /// Create a search filter with a [`CommandLineSearch`] pub fn from_text_search(cmd: CommandLineSearch) -> SearchFilter { @@ -61,8 +62,9 @@ impl SearchFilter { s.command_line = Some(cmd); s } + /// No filter constraint - pub fn anything() -> SearchFilter { + pub const fn anything() -> SearchFilter { SearchFilter { command_line: None, not_command_line: None, @@ -106,8 +108,9 @@ impl SearchQuery { filter: SearchFilter::from_text_search(CommandLineSearch::Substring(contains)), } } + /// Get the most recent entry matching [`SearchFilter`] - pub fn last_with_search(filter: SearchFilter) -> SearchQuery { + pub const fn last_with_search(filter: SearchFilter) -> SearchQuery { SearchQuery { direction: SearchDirection::Backward, start_time: None, @@ -118,14 +121,16 @@ impl SearchQuery { filter, } } + /// Get the most recent entry starting with the `prefix` pub fn last_with_prefix(prefix: String) -> SearchQuery { SearchQuery::last_with_search(SearchFilter::from_text_search(CommandLineSearch::Prefix( prefix, ))) } + /// Query to get all entries in the given [`SearchDirection`] - pub fn everything(direction: SearchDirection) -> SearchQuery { + pub const fn everything(direction: SearchDirection) -> SearchQuery { SearchQuery { direction, start_time: None, diff --git a/src/history/cursor.rs b/src/history/cursor.rs index 0f1ca61..8181a23 100644 --- a/src/history/cursor.rs +++ b/src/history/cursor.rs @@ -16,7 +16,7 @@ pub struct HistoryCursor { } impl HistoryCursor { - pub fn new(query: HistoryNavigationQuery) -> HistoryCursor { + pub const fn new(query: HistoryNavigationQuery) -> HistoryCursor { HistoryCursor { query, current: None, diff --git a/src/history/item.rs b/src/history/item.rs index 16cd54b..c4f4c19 100644 --- a/src/history/item.rs +++ b/src/history/item.rs @@ -6,7 +6,7 @@ use std::{fmt::Display, time::Duration}; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct HistoryItemId(pub(crate) i64); impl HistoryItemId { - pub(crate) fn new(i: i64) -> HistoryItemId { + pub(crate) const fn new(i: i64) -> HistoryItemId { HistoryItemId(i) } } @@ -21,7 +21,7 @@ impl Display for HistoryItemId { #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct HistorySessionId(pub(crate) i64); impl HistorySessionId { - pub(crate) fn new(i: i64) -> HistorySessionId { + pub(crate) const fn new(i: i64) -> HistorySessionId { HistorySessionId(i) } } diff --git a/src/painting/styled_text.rs b/src/painting/styled_text.rs index 5874f1b..eeb8807 100644 --- a/src/painting/styled_text.rs +++ b/src/painting/styled_text.rs @@ -18,7 +18,7 @@ impl Default for StyledText { impl StyledText { /// Construct a new `StyledText` - pub fn new() -> Self { + pub const fn new() -> Self { Self { buffer: vec![] } } diff --git a/src/prompt/base.rs b/src/prompt/base.rs index f5f4a84..0ba570c 100644 --- a/src/prompt/base.rs +++ b/src/prompt/base.rs @@ -34,7 +34,7 @@ pub struct PromptHistorySearch { impl PromptHistorySearch { /// A constructor to create a history search - pub fn new(status: PromptHistorySearchStatus, search_term: String) -> Self { + pub const fn new(status: PromptHistorySearchStatus, search_term: String) -> Self { PromptHistorySearch { status, term: search_term, diff --git a/src/prompt/default.rs b/src/prompt/default.rs index 7793a79..f56ae90 100644 --- a/src/prompt/default.rs +++ b/src/prompt/default.rs @@ -104,7 +104,7 @@ impl DefaultPrompt { /// Constructor for the default prompt, which takes a configurable left and right prompt. /// For less customization, use [`DefaultPrompt::default`]. /// For more fine-tuned configuration, implement the [`Prompt`] trait. - pub fn new( + pub const fn new( left_prompt: DefaultPromptSegment, right_prompt: DefaultPromptSegment, ) -> DefaultPrompt {