Add const to some new functions. (#555)

* Add const to some new functions.

* Add const to SearchFilter builders.

* Add const to SearchQuery builders.
This commit is contained in:
Jérémy Audiger 2023-03-22 19:23:44 +01:00 committed by GitHub
parent 781e73a2be
commit 31743c8488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 16 additions and 11 deletions

View File

@ -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
}

View File

@ -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 }
}
}

View File

@ -54,6 +54,7 @@ pub struct SearchFilter {
/// Filter whether the command completed
pub exit_successful: Option<bool>,
}
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,

View File

@ -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,

View File

@ -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)
}
}

View File

@ -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![] }
}

View File

@ -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,

View File

@ -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 {