mirror of
https://github.com/nushell/reedline.git
synced 2024-10-27 01:45:51 +03:00
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:
parent
781e73a2be
commit
31743c8488
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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![] }
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user