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 { impl Editor {
/// Get the current [`LineBuffer`] /// Get the current [`LineBuffer`]
pub fn line_buffer(&self) -> &LineBuffer { pub const fn line_buffer(&self) -> &LineBuffer {
&self.line_buffer &self.line_buffer
} }

View File

@ -162,7 +162,7 @@ impl EditMode for Emacs {
impl Emacs { impl Emacs {
/// Emacs style input parsing constructor if you want to use custom keybindings /// 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 } Emacs { keybindings }
} }
} }

View File

@ -54,6 +54,7 @@ pub struct SearchFilter {
/// Filter whether the command completed /// Filter whether the command completed
pub exit_successful: Option<bool>, pub exit_successful: Option<bool>,
} }
impl SearchFilter { impl SearchFilter {
/// Create a search filter with a [`CommandLineSearch`] /// Create a search filter with a [`CommandLineSearch`]
pub fn from_text_search(cmd: CommandLineSearch) -> SearchFilter { pub fn from_text_search(cmd: CommandLineSearch) -> SearchFilter {
@ -61,8 +62,9 @@ impl SearchFilter {
s.command_line = Some(cmd); s.command_line = Some(cmd);
s s
} }
/// No filter constraint /// No filter constraint
pub fn anything() -> SearchFilter { pub const fn anything() -> SearchFilter {
SearchFilter { SearchFilter {
command_line: None, command_line: None,
not_command_line: None, not_command_line: None,
@ -106,8 +108,9 @@ impl SearchQuery {
filter: SearchFilter::from_text_search(CommandLineSearch::Substring(contains)), filter: SearchFilter::from_text_search(CommandLineSearch::Substring(contains)),
} }
} }
/// Get the most recent entry matching [`SearchFilter`] /// 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 { SearchQuery {
direction: SearchDirection::Backward, direction: SearchDirection::Backward,
start_time: None, start_time: None,
@ -118,14 +121,16 @@ impl SearchQuery {
filter, filter,
} }
} }
/// Get the most recent entry starting with the `prefix` /// Get the most recent entry starting with the `prefix`
pub fn last_with_prefix(prefix: String) -> SearchQuery { pub fn last_with_prefix(prefix: String) -> SearchQuery {
SearchQuery::last_with_search(SearchFilter::from_text_search(CommandLineSearch::Prefix( SearchQuery::last_with_search(SearchFilter::from_text_search(CommandLineSearch::Prefix(
prefix, prefix,
))) )))
} }
/// Query to get all entries in the given [`SearchDirection`] /// Query to get all entries in the given [`SearchDirection`]
pub fn everything(direction: SearchDirection) -> SearchQuery { pub const fn everything(direction: SearchDirection) -> SearchQuery {
SearchQuery { SearchQuery {
direction, direction,
start_time: None, start_time: None,

View File

@ -16,7 +16,7 @@ pub struct HistoryCursor {
} }
impl HistoryCursor { impl HistoryCursor {
pub fn new(query: HistoryNavigationQuery) -> HistoryCursor { pub const fn new(query: HistoryNavigationQuery) -> HistoryCursor {
HistoryCursor { HistoryCursor {
query, query,
current: None, current: None,

View File

@ -6,7 +6,7 @@ use std::{fmt::Display, time::Duration};
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct HistoryItemId(pub(crate) i64); pub struct HistoryItemId(pub(crate) i64);
impl HistoryItemId { impl HistoryItemId {
pub(crate) fn new(i: i64) -> HistoryItemId { pub(crate) const fn new(i: i64) -> HistoryItemId {
HistoryItemId(i) HistoryItemId(i)
} }
} }
@ -21,7 +21,7 @@ impl Display for HistoryItemId {
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct HistorySessionId(pub(crate) i64); pub struct HistorySessionId(pub(crate) i64);
impl HistorySessionId { impl HistorySessionId {
pub(crate) fn new(i: i64) -> HistorySessionId { pub(crate) const fn new(i: i64) -> HistorySessionId {
HistorySessionId(i) HistorySessionId(i)
} }
} }

View File

@ -18,7 +18,7 @@ impl Default for StyledText {
impl StyledText { impl StyledText {
/// Construct a new `StyledText` /// Construct a new `StyledText`
pub fn new() -> Self { pub const fn new() -> Self {
Self { buffer: vec![] } Self { buffer: vec![] }
} }

View File

@ -34,7 +34,7 @@ pub struct PromptHistorySearch {
impl PromptHistorySearch { impl PromptHistorySearch {
/// A constructor to create a history search /// 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 { PromptHistorySearch {
status, status,
term: search_term, term: search_term,

View File

@ -104,7 +104,7 @@ impl DefaultPrompt {
/// Constructor for the default prompt, which takes a configurable left and right prompt. /// Constructor for the default prompt, which takes a configurable left and right prompt.
/// For less customization, use [`DefaultPrompt::default`]. /// For less customization, use [`DefaultPrompt::default`].
/// For more fine-tuned configuration, implement the [`Prompt`] trait. /// For more fine-tuned configuration, implement the [`Prompt`] trait.
pub fn new( pub const fn new(
left_prompt: DefaultPromptSegment, left_prompt: DefaultPromptSegment,
right_prompt: DefaultPromptSegment, right_prompt: DefaultPromptSegment,
) -> DefaultPrompt { ) -> DefaultPrompt {