diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-13 00:58:32 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-13 00:58:32 +0200 |
| commit | 9352a0f7cfdd5f5fc102a25d8a93218bc3dbe462 (patch) | |
| tree | b998430c307c10defb79d91abe5d30471c5c4f12 | |
| parent | chore(treewide): Remove `cargo` warnings to 0 (diff) | |
| download | atuin-9352a0f7cfdd5f5fc102a25d8a93218bc3dbe462.zip | |
chore(treewide): Fix some of `clippy`'s error
Just a run of `cargo clippy --fix`
26 files changed, 270 insertions, 270 deletions
diff --git a/crates/turtle/src/atuin_client/database.rs b/crates/turtle/src/atuin_client/database.rs index 6a2d5887..24f017be 100644 --- a/crates/turtle/src/atuin_client/database.rs +++ b/crates/turtle/src/atuin_client/database.rs @@ -74,7 +74,7 @@ pub(crate) async fn current_context() -> eyre::Result<Context> { impl Context { pub(crate) fn from_history(entry: &History) -> Self { - Context { + Self { session: entry.session.clone(), cwd: entry.cwd.clone(), hostname: entry.hostname.clone(), @@ -89,7 +89,7 @@ fn get_session_start_time(session_id: &str) -> Option<i64> { && let Some(timestamp) = uuid.get_timestamp() { let (seconds, nanos) = timestamp.to_unix(); - return Some(seconds as i64 * 1_000_000_000 + nanos as i64); + return Some(seconds as i64 * 1_000_000_000 + i64::from(nanos)); } None } @@ -205,7 +205,7 @@ impl ClientSqlite { .author(author) .intent(intent) .deleted_at( - deleted_at.and_then(|t| OffsetDateTime::from_unix_timestamp_nanos(t as i128).ok()), + deleted_at.and_then(|t| OffsetDateTime::from_unix_timestamp_nanos(i128::from(t)).ok()), ) .build() .into() diff --git a/crates/turtle/src/atuin_client/history.rs b/crates/turtle/src/atuin_client/history.rs index 11d60548..c38d8ccc 100644 --- a/crates/turtle/src/atuin_client/history.rs +++ b/crates/turtle/src/atuin_client/history.rs @@ -223,7 +223,7 @@ impl History { } } - fn deserialize_v0(bytes: &[u8]) -> Result<History> { + fn deserialize_v0(bytes: &[u8]) -> Result<Self> { use rmp::decode; fn error_report<E: std::fmt::Debug>(err: E) -> eyre::Report { @@ -270,7 +270,7 @@ impl History { bail!("trailing bytes in encoded history. malformed") } - Ok(History { + Ok(Self { id: id.to_owned().into(), timestamp: OffsetDateTime::from_unix_timestamp_nanos(i128::from(timestamp))?, duration, @@ -287,7 +287,7 @@ impl History { }) } - fn deserialize_v1(bytes: &[u8]) -> Result<History> { + fn deserialize_v1(bytes: &[u8]) -> Result<Self> { use rmp::decode; fn error_report<E: std::fmt::Debug>(err: E) -> eyre::Report { @@ -341,7 +341,7 @@ impl History { bail!("trailing bytes in encoded history. malformed") } - Ok(History { + Ok(Self { id: id.to_owned().into(), timestamp: OffsetDateTime::from_unix_timestamp_nanos(i128::from(timestamp))?, duration, @@ -358,7 +358,7 @@ impl History { }) } - pub(crate) fn deserialize(bytes: &[u8], version: &str) -> Result<History> { + pub(crate) fn deserialize(bytes: &[u8], version: &str) -> Result<Self> { match version { HISTORY_VERSION_V0 => Self::deserialize_v0(bytes), HISTORY_VERSION_V1 => Self::deserialize_v1(bytes), diff --git a/crates/turtle/src/atuin_client/history/builder.rs b/crates/turtle/src/atuin_client/history/builder.rs index 50a9d2af..daa4ef49 100644 --- a/crates/turtle/src/atuin_client/history/builder.rs +++ b/crates/turtle/src/atuin_client/history/builder.rs @@ -28,7 +28,7 @@ pub(crate) struct HistoryImported { impl From<HistoryImported> for History { fn from(imported: HistoryImported) -> Self { - History::new( + Self::new( imported.timestamp, imported.command, imported.cwd, @@ -63,7 +63,7 @@ pub(crate) struct HistoryCaptured { impl From<HistoryCaptured> for History { fn from(captured: HistoryCaptured) -> Self { - History::new( + Self::new( captured.timestamp, captured.command, captured.cwd, @@ -98,7 +98,7 @@ pub(crate) struct HistoryFromDb { impl From<HistoryFromDb> for History { fn from(from_db: HistoryFromDb) -> Self { - History { + Self { id: from_db.id.into(), timestamp: from_db.timestamp, exit: from_db.exit, @@ -117,7 +117,7 @@ impl From<HistoryFromDb> for History { /// Builder for a history entry that is captured via hook and sent to the daemon /// /// This builder is similar to Capture, but we just require more information up front. -/// For the old setup, we could just rely on History::new to read some of the missing +/// For the old setup, we could just rely on `History::new` to read some of the missing /// data. This is no longer the case. #[derive(Debug, Clone, TypedBuilder)] pub(crate) struct HistoryDaemonCapture { @@ -138,7 +138,7 @@ pub(crate) struct HistoryDaemonCapture { impl From<HistoryDaemonCapture> for History { fn from(captured: HistoryDaemonCapture) -> Self { - History::new( + Self::new( captured.timestamp, captured.command, captured.cwd, diff --git a/crates/turtle/src/atuin_client/settings.rs b/crates/turtle/src/atuin_client/settings.rs index 074b2634..bfb8d001 100644 --- a/crates/turtle/src/atuin_client/settings.rs +++ b/crates/turtle/src/atuin_client/settings.rs @@ -49,25 +49,25 @@ pub(crate) enum SearchMode { impl SearchMode { pub(crate) fn as_str(self) -> &'static str { match self { - SearchMode::Prefix => "PREFIX", - SearchMode::FullText => "FULLTXT", - SearchMode::Fuzzy => "FUZZY", - SearchMode::Skim => "SKIM", - SearchMode::DaemonFuzzy => "DAEMON", + Self::Prefix => "PREFIX", + Self::FullText => "FULLTXT", + Self::Fuzzy => "FUZZY", + Self::Skim => "SKIM", + Self::DaemonFuzzy => "DAEMON", } } pub(crate) fn next(self, settings: &Settings) -> Self { match self { - SearchMode::Prefix => SearchMode::FullText, + Self::Prefix => Self::FullText, // if the user is using skim, we go to skim - SearchMode::FullText if settings.search_mode == SearchMode::Skim => SearchMode::Skim, + Self::FullText if settings.search_mode == Self::Skim => Self::Skim, // if the user is using daemon-fuzzy, we go to daemon-fuzzy - SearchMode::FullText if settings.search_mode == SearchMode::DaemonFuzzy => { - SearchMode::DaemonFuzzy + Self::FullText if settings.search_mode == Self::DaemonFuzzy => { + Self::DaemonFuzzy } // otherwise fuzzy. - SearchMode::FullText => SearchMode::Fuzzy, - SearchMode::Fuzzy | SearchMode::Skim | SearchMode::DaemonFuzzy => SearchMode::Prefix, + Self::FullText => Self::Fuzzy, + Self::Fuzzy | Self::Skim | Self::DaemonFuzzy => Self::Prefix, } } } @@ -96,12 +96,12 @@ pub(crate) enum FilterMode { impl FilterMode { pub(crate) fn as_str(self) -> &'static str { match self { - FilterMode::Global => "GLOBAL", - FilterMode::Host => "HOST", - FilterMode::Session => "SESSION", - FilterMode::Directory => "DIRECTORY", - FilterMode::Workspace => "WORKSPACE", - FilterMode::SessionPreload => "SESSION+", + Self::Global => "GLOBAL", + Self::Host => "HOST", + Self::Session => "SESSION", + Self::Directory => "DIRECTORY", + Self::Workspace => "WORKSPACE", + Self::SessionPreload => "SESSION+", } } } @@ -127,10 +127,10 @@ pub(crate) enum Dialect { } impl From<Dialect> for interim::Dialect { - fn from(d: Dialect) -> interim::Dialect { + fn from(d: Dialect) -> Self { match d { - Dialect::Uk => interim::Dialect::Uk, - Dialect::Us => interim::Dialect::Us, + Dialect::Uk => Self::Uk, + Dialect::Us => Self::Us, } } } @@ -324,7 +324,7 @@ impl Keys { /// The standard default values for all `[keys]` options. /// These match the config defaults set in `builder_with_data_dir()`. pub(crate) fn standard_defaults() -> Self { - Keys { + Self { scroll_exits: true, exit_past_line_start: true, accept_past_line_end: true, @@ -443,11 +443,11 @@ impl LogLevel { /// Convert to a tracing directive string for use with [`EnvFilter`]. pub(crate) fn as_directive(self) -> &'static str { match self { - LogLevel::Trace => "trace", - LogLevel::Debug => "debug", - LogLevel::Info => "info", - LogLevel::Warn => "warn", - LogLevel::Error => "error", + Self::Trace => "trace", + Self::Debug => "debug", + Self::Info => "info", + Self::Warn => "warn", + Self::Error => "error", } } } @@ -643,20 +643,20 @@ impl UiColumnType { /// The Command column returns 0 as it expands to fill remaining space. pub(crate) fn default_width(self) -> u16 { match self { - UiColumnType::Duration => 5, // "814ms" - UiColumnType::Time => 9, // "459ms ago" - UiColumnType::Datetime => 16, // "2025-01-22 14:35" - UiColumnType::Directory => 20, - UiColumnType::Host => 15, - UiColumnType::User => 10, - UiColumnType::Exit => { + Self::Duration => 5, // "814ms" + Self::Time => 9, // "459ms ago" + Self::Datetime => 16, // "2025-01-22 14:35" + Self::Directory => 20, + Self::Host => 15, + Self::User => 10, + Self::Exit => { if cfg!(windows) { 11 // 32-bit integer on Windows: "-1978335212" } else { 3 // Usually a byte on Unix } } - UiColumnType::Command => 0, // Expands to fill + Self::Command => 0, // Expands to fill } } } @@ -1289,7 +1289,7 @@ impl Settings { pub(crate) fn new() -> Result<Self> { let config = Self::build_config()?; - let settings: Settings = config + let settings: Self = config .try_deserialize() .map_err(|e| eyre!("failed to deserialize: {}", e))?; diff --git a/crates/turtle/src/atuin_common/record.rs b/crates/turtle/src/atuin_common/record.rs index 7b2a1a10..f8f9f8a7 100644 --- a/crates/turtle/src/atuin_common/record.rs +++ b/crates/turtle/src/atuin_common/record.rs @@ -106,8 +106,8 @@ impl Extend<(HostId, String, RecordIdx)> for RecordStatus { } impl RecordStatus { - pub(crate) fn new() -> RecordStatus { - RecordStatus { + pub(crate) fn new() -> Self { + Self { hosts: HashMap::new(), } } @@ -246,7 +246,7 @@ impl Record<EncryptedData> { self, old_key: &[u8; 32], new_key: &[u8; 32], - ) -> Result<Record<EncryptedData>> { + ) -> Result<Self> { let ad = AdditionalData { id: &self.id, version: &self.version, @@ -254,7 +254,7 @@ impl Record<EncryptedData> { host: &self.host.id, idx: &self.idx, }; - Ok(Record { + Ok(Self { data: E::re_encrypt(self.data, ad, old_key, new_key)?, id: self.id, host: self.host, diff --git a/crates/turtle/src/atuin_common/shell.rs b/crates/turtle/src/atuin_common/shell.rs index d259b99e..880ff00f 100644 --- a/crates/turtle/src/atuin_common/shell.rs +++ b/crates/turtle/src/atuin_common/shell.rs @@ -14,15 +14,15 @@ pub(crate) enum Shell { impl std::fmt::Display for Shell { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let shell = match self { - Shell::Bash => "bash", - Shell::Fish => "fish", - Shell::Zsh => "zsh", - Shell::Nu => "nu", - Shell::Xonsh => "xonsh", - Shell::Sh => "sh", - Shell::Powershell => "powershell", + Self::Bash => "bash", + Self::Fish => "fish", + Self::Zsh => "zsh", + Self::Nu => "nu", + Self::Xonsh => "xonsh", + Self::Sh => "sh", + Self::Powershell => "powershell", - Shell::Unknown => "unknown", + Self::Unknown => "unknown", }; write!(f, "{shell}") @@ -30,23 +30,23 @@ impl std::fmt::Display for Shell { } impl Shell { - pub(crate) fn from_env() -> Shell { - std::env::var("ATUIN_SHELL").map_or(Shell::Unknown, |shell| { - Shell::from_string(shell.trim().to_lowercase().as_str()) + pub(crate) fn from_env() -> Self { + std::env::var("ATUIN_SHELL").map_or(Self::Unknown, |shell| { + Self::from_string(shell.trim().to_lowercase().as_str()) }) } - pub(crate) fn from_string(name: &str) -> Shell { + pub(crate) fn from_string(name: &str) -> Self { match name { - "bash" => Shell::Bash, - "fish" => Shell::Fish, - "zsh" => Shell::Zsh, - "xonsh" => Shell::Xonsh, - "nu" => Shell::Nu, - "sh" => Shell::Sh, - "powershell" => Shell::Powershell, + "bash" => Self::Bash, + "fish" => Self::Fish, + "zsh" => Self::Zsh, + "xonsh" => Self::Xonsh, + "nu" => Self::Nu, + "sh" => Self::Sh, + "powershell" => Self::Powershell, - _ => Shell::Unknown, + _ => Self::Unknown, } } } diff --git a/crates/turtle/src/atuin_common/utils.rs b/crates/turtle/src/atuin_common/utils.rs index c8c2776e..aa662979 100644 --- a/crates/turtle/src/atuin_common/utils.rs +++ b/crates/turtle/src/atuin_common/utils.rs @@ -106,7 +106,7 @@ pub(crate) fn get_current_dir() -> String { Ok(v) => v, Err(_) => match env::current_dir() { Ok(dir) => dir.display().to_string(), - Err(_) => String::from(""), + Err(_) => String::new(), }, } } @@ -124,9 +124,7 @@ pub(crate) fn broken_symlink<P: Into<PathBuf>>(path: P) -> bool { /// reflect the actual command run rather than just the printable characters. pub(crate) trait Escapable: AsRef<str> { fn escape_control(&self) -> Cow<'_, str> { - if !self.as_ref().contains(|c: char| c.is_ascii_control()) { - self.as_ref().into() - } else { + if self.as_ref().contains(|c: char| c.is_ascii_control()) { let mut remaining = self.as_ref(); // Not a perfect way to reserve space but should reduce the allocations let mut buf = String::with_capacity(remaining.len()); @@ -142,6 +140,8 @@ pub(crate) trait Escapable: AsRef<str> { } buf.push_str(remaining); buf.into() + } else { + self.as_ref().into() } } } diff --git a/crates/turtle/src/atuin_daemon/client.rs b/crates/turtle/src/atuin_daemon/client.rs index 4ec1a60b..2ea7ffc5 100644 --- a/crates/turtle/src/atuin_daemon/client.rs +++ b/crates/turtle/src/atuin_daemon/client.rs @@ -97,7 +97,7 @@ impl HistoryClient { let client = HistoryServiceClient::new(channel); - Ok(HistoryClient { client }) + Ok(Self { client }) } pub(crate) async fn start_history(&mut self, h: History) -> Result<StartHistoryReply> { @@ -169,7 +169,7 @@ impl SearchClient { let client = SearchServiceClient::new(channel); - Ok(SearchClient { client }) + Ok(Self { client }) } #[instrument(skip_all, level = Level::TRACE, name = "daemon_client_search", fields(query = %query, query_id = query_id))] @@ -198,19 +198,19 @@ impl SearchClient { impl From<FilterMode> for RpcFilterMode { fn from(filter_mode: FilterMode) -> Self { match filter_mode { - FilterMode::Global => RpcFilterMode::Global, - FilterMode::Host => RpcFilterMode::Host, - FilterMode::Session => RpcFilterMode::Session, - FilterMode::Directory => RpcFilterMode::Directory, - FilterMode::Workspace => RpcFilterMode::Workspace, - FilterMode::SessionPreload => RpcFilterMode::SessionPreload, + FilterMode::Global => Self::Global, + FilterMode::Host => Self::Host, + FilterMode::Session => Self::Session, + FilterMode::Directory => Self::Directory, + FilterMode::Workspace => Self::Workspace, + FilterMode::SessionPreload => Self::SessionPreload, } } } impl From<Context> for RpcSearchContext { fn from(context: Context) -> Self { - RpcSearchContext { + Self { session_id: context.session, cwd: context.cwd, hostname: context.hostname, @@ -248,7 +248,7 @@ impl SemanticClient { let client = SemanticServiceClient::new(channel); - Ok(SemanticClient { client }) + Ok(Self { client }) } #[cfg(unix)] @@ -299,7 +299,7 @@ impl ControlClient { let client = ControlServiceClient::new(channel); - Ok(ControlClient { client }) + Ok(Self { client }) } /// Connect using settings. diff --git a/crates/turtle/src/atuin_daemon/components/search.rs b/crates/turtle/src/atuin_daemon/components/search.rs index 39df758b..bcb18865 100644 --- a/crates/turtle/src/atuin_daemon/components/search.rs +++ b/crates/turtle/src/atuin_daemon/components/search.rs @@ -365,7 +365,7 @@ impl SearchSvc for SearchGrpcService { } } -/// Convert proto FilterMode and context to IndexFilterMode. +/// Convert proto `FilterMode` and context to `IndexFilterMode`. fn convert_filter_mode( mode: FilterMode, context: &Option<search::SearchContext>, @@ -399,6 +399,6 @@ pub(crate) fn with_trailing_slash(s: &str) -> String { if s.ends_with('/') { s.to_string() } else { - format!("{}/", s) + format!("{s}/") } } diff --git a/crates/turtle/src/atuin_daemon/components/sync.rs b/crates/turtle/src/atuin_daemon/components/sync.rs index 8b5b621d..933d5ae1 100644 --- a/crates/turtle/src/atuin_daemon/components/sync.rs +++ b/crates/turtle/src/atuin_daemon/components/sync.rs @@ -130,7 +130,7 @@ async fn sync_loop(handle: DaemonHandle, mut cmd_rx: mpsc::Receiver<SyncCommand> let history_store = HistoryStore::new(handle.store().clone(), host_id, encryption_key); // Don't backoff by more than 30 mins (with a random jitter of up to 1 min) - let max_interval: f64 = 60.0 * 30.0 + rand::thread_rng().gen_range(0.0..60.0); + let max_interval: f64 = 60.0f64.mul_add(30.0, rand::thread_rng().gen_range(0.0..60.0)); let mut ticker = time::interval(Duration::from_secs(settings.daemon.sync_frequency)); diff --git a/crates/turtle/src/atuin_daemon/search/mod.rs b/crates/turtle/src/atuin_daemon/search/mod.rs index 60d923cd..04beb459 100644 --- a/crates/turtle/src/atuin_daemon/search/mod.rs +++ b/crates/turtle/src/atuin_daemon/search/mod.rs @@ -93,7 +93,7 @@ impl FrecencyData { let frequency_score = (f64::from(self.count).ln() * 20.0).min(100.0); // Apply multipliers and combine scores, then round to u32 - ((recency_score * recency_mul) + (frequency_score * frequency_mul)).round() as u32 + recency_score.mul_add(recency_mul, frequency_score * frequency_mul).round() as u32 } } @@ -261,8 +261,8 @@ type FrecencyMap = Arc<HashMap<Arc<str>, u32>>; /// although this should never happen due to precomputing the frecency map. pub(crate) struct SearchIndex { /// Map from command text to command data. - /// Using DashMap for concurrent read/write access, wrapped in Arc for sharing with scorer. - /// Keys are Arc<str> to enable zero-copy sharing with frecency_map. + /// Using `DashMap` for concurrent read/write access, wrapped in Arc for sharing with scorer. + /// Keys are Arc<str> to enable zero-copy sharing with `frecency_map`. commands: Arc<DashMap<Arc<str>, CommandData>>, /// Nucleo fuzzy matcher - items are command strings. nucleo: RwLock<Nucleo<String>>, @@ -416,7 +416,7 @@ impl SearchIndex { .global_frecency .compute(now, recency_mul, frequency_mul); // Apply overall frecency multiplier and round to u32 - let frecency = (frecency as f64 * frecency_mul).round() as u32; + let frecency = (f64::from(frecency) * frecency_mul).round() as u32; // Arc::clone is cheap - just increments reference count frecency_map.insert(Arc::clone(entry.key()), frecency); } diff --git a/crates/turtle/src/atuin_history/stats.rs b/crates/turtle/src/atuin_history/stats.rs index a19d2d0e..c53dafb2 100644 --- a/crates/turtle/src/atuin_history/stats.rs +++ b/crates/turtle/src/atuin_history/stats.rs @@ -271,7 +271,7 @@ pub(crate) fn compute( total_commands: total_unignored, top: top .into_iter() - .map(|t| (t.0.into_iter().map(|s| s.to_string()).collect(), t.1)) + .map(|t| (t.0.into_iter().map(ToString::to_string).collect(), t.1)) .collect(), }) } diff --git a/crates/turtle/src/atuin_server/database/db/mod.rs b/crates/turtle/src/atuin_server/database/db/mod.rs index 47dbd6d1..77bd0c61 100644 --- a/crates/turtle/src/atuin_server/database/db/mod.rs +++ b/crates/turtle/src/atuin_server/database/db/mod.rs @@ -25,7 +25,7 @@ pub(crate) struct ServerPostgres { impl ServerPostgres { /// Returns the appropriate pool for read operations. - /// Uses read_pool if available, otherwise falls back to the primary pool. + /// Uses `read_pool` if available, otherwise falls back to the primary pool. fn read_pool(&self) -> &sqlx::Pool<sqlx::postgres::Postgres> { self.read_pool.as_ref().unwrap_or(&self.pool) } diff --git a/crates/turtle/src/atuin_server/database/db/wrappers.rs b/crates/turtle/src/atuin_server/database/db/wrappers.rs index 0a7b6ff3..0315e331 100644 --- a/crates/turtle/src/atuin_server/database/db/wrappers.rs +++ b/crates/turtle/src/atuin_server/database/db/wrappers.rs @@ -26,7 +26,7 @@ impl<'a> ::sqlx::FromRow<'a, PgRow> for DbRecord { } impl From<DbRecord> for Record<EncryptedData> { - fn from(other: DbRecord) -> Record<EncryptedData> { - Record { ..other.0 } + fn from(other: DbRecord) -> Self { + other.0 } } diff --git a/crates/turtle/src/atuin_server/handlers/mod.rs b/crates/turtle/src/atuin_server/handlers/mod.rs index 7aded3de..b73df27b 100644 --- a/crates/turtle/src/atuin_server/handlers/mod.rs +++ b/crates/turtle/src/atuin_server/handlers/mod.rs @@ -46,7 +46,7 @@ impl<'a> RespExt<'a> for ErrorResponse<'a> { } } - fn reply(reason: &'a str) -> ErrorResponse<'a> { + fn reply(reason: &'a str) -> Self { Self { reason: reason.into(), } diff --git a/crates/turtle/src/atuin_server/metrics.rs b/crates/turtle/src/atuin_server/metrics.rs index 7a9dc571..556de6fb 100644 --- a/crates/turtle/src/atuin_server/metrics.rs +++ b/crates/turtle/src/atuin_server/metrics.rs @@ -24,7 +24,7 @@ pub(crate) fn setup_metrics_recorder() -> PrometheusHandle { /// Middleware to record some common HTTP metrics /// Generic over B to allow for arbitrary body types (eg Vec<u8>, Streams, a deserialized thing, etc) -/// Someday tower-http might provide a metrics middleware: https://github.com/tower-rs/tower-http/issues/57 +/// Someday tower-http might provide a metrics middleware: <https://github.com/tower-rs/tower-http/issues/57> pub(crate) async fn track_metrics(req: Request, next: Next) -> impl IntoResponse { let start = Instant::now(); diff --git a/crates/turtle/src/atuin_server/router.rs b/crates/turtle/src/atuin_server/router.rs index d9cfc979..d6fe9482 100644 --- a/crates/turtle/src/atuin_server/router.rs +++ b/crates/turtle/src/atuin_server/router.rs @@ -45,7 +45,7 @@ impl FromRequestParts<AppState> for UserAuth { let user = User { id: user_id }; - Ok(UserAuth(user)) + Ok(Self(user)) } } diff --git a/crates/turtle/src/command/client/search/engines/daemon.rs b/crates/turtle/src/command/client/search/engines/daemon.rs index 55b3c6f2..cb0fdf7d 100644 --- a/crates/turtle/src/command/client/search/engines/daemon.rs +++ b/crates/turtle/src/command/client/search/engines/daemon.rs @@ -26,7 +26,7 @@ pub(crate) struct Search { impl Search { pub(crate) fn new(settings: &Settings) -> Self { - Search { + Self { client: None, query_id: 0, settings: settings.clone(), diff --git a/crates/turtle/src/command/client/search/engines/skim.rs b/crates/turtle/src/command/client/search/engines/skim.rs index 739e790b..e090e40d 100644 --- a/crates/turtle/src/command/client/search/engines/skim.rs +++ b/crates/turtle/src/command/client/search/engines/skim.rs @@ -18,7 +18,7 @@ pub(crate) struct Search { impl Search { pub(crate) fn new() -> Self { - Search { + Self { all_history: vec![], engine: SkimMatcherV2::default(), } diff --git a/crates/turtle/src/command/client/search/keybindings/actions.rs b/crates/turtle/src/command/client/search/keybindings/actions.rs index 341b030c..e9b654c5 100644 --- a/crates/turtle/src/command/client/search/keybindings/actions.rs +++ b/crates/turtle/src/command/client/search/keybindings/actions.rs @@ -83,73 +83,73 @@ impl Action { && let Ok(n) = rest.parse::<u8>() && (1..=9).contains(&n) { - return Ok(Action::AcceptNth(n)); + return Ok(Self::AcceptNth(n)); } if let Some(rest) = s.strip_prefix("return-selection-") && let Ok(n) = rest.parse::<u8>() && (1..=9).contains(&n) { - return Ok(Action::ReturnSelectionNth(n)); + return Ok(Self::ReturnSelectionNth(n)); } match s { - "cursor-left" => Ok(Action::CursorLeft), - "cursor-right" => Ok(Action::CursorRight), - "cursor-word-left" => Ok(Action::CursorWordLeft), - "cursor-word-right" => Ok(Action::CursorWordRight), - "cursor-word-end" => Ok(Action::CursorWordEnd), - "cursor-start" => Ok(Action::CursorStart), - "cursor-end" => Ok(Action::CursorEnd), + "cursor-left" => Ok(Self::CursorLeft), + "cursor-right" => Ok(Self::CursorRight), + "cursor-word-left" => Ok(Self::CursorWordLeft), + "cursor-word-right" => Ok(Self::CursorWordRight), + "cursor-word-end" => Ok(Self::CursorWordEnd), + "cursor-start" => Ok(Self::CursorStart), + "cursor-end" => Ok(Self::CursorEnd), - "delete-char-before" => Ok(Action::DeleteCharBefore), - "delete-char-after" => Ok(Action::DeleteCharAfter), - "delete-word-before" => Ok(Action::DeleteWordBefore), - "delete-word-after" => Ok(Action::DeleteWordAfter), - "delete-to-word-boundary" => Ok(Action::DeleteToWordBoundary), - "clear-line" => Ok(Action::ClearLine), - "clear-to-start" => Ok(Action::ClearToStart), - "clear-to-end" => Ok(Action::ClearToEnd), + "delete-char-before" => Ok(Self::DeleteCharBefore), + "delete-char-after" => Ok(Self::DeleteCharAfter), + "delete-word-before" => Ok(Self::DeleteWordBefore), + "delete-word-after" => Ok(Self::DeleteWordAfter), + "delete-to-word-boundary" => Ok(Self::DeleteToWordBoundary), + "clear-line" => Ok(Self::ClearLine), + "clear-to-start" => Ok(Self::ClearToStart), + "clear-to-end" => Ok(Self::ClearToEnd), - "select-next" => Ok(Action::SelectNext), - "select-previous" => Ok(Action::SelectPrevious), - "scroll-half-page-up" => Ok(Action::ScrollHalfPageUp), - "scroll-half-page-down" => Ok(Action::ScrollHalfPageDown), - "scroll-page-up" => Ok(Action::ScrollPageUp), - "scroll-page-down" => Ok(Action::ScrollPageDown), - "scroll-to-top" => Ok(Action::ScrollToTop), - "scroll-to-bottom" => Ok(Action::ScrollToBottom), - "scroll-to-screen-top" => Ok(Action::ScrollToScreenTop), - "scroll-to-screen-middle" => Ok(Action::ScrollToScreenMiddle), - "scroll-to-screen-bottom" => Ok(Action::ScrollToScreenBottom), + "select-next" => Ok(Self::SelectNext), + "select-previous" => Ok(Self::SelectPrevious), + "scroll-half-page-up" => Ok(Self::ScrollHalfPageUp), + "scroll-half-page-down" => Ok(Self::ScrollHalfPageDown), + "scroll-page-up" => Ok(Self::ScrollPageUp), + "scroll-page-down" => Ok(Self::ScrollPageDown), + "scroll-to-top" => Ok(Self::ScrollToTop), + "scroll-to-bottom" => Ok(Self::ScrollToBottom), + "scroll-to-screen-top" => Ok(Self::ScrollToScreenTop), + "scroll-to-screen-middle" => Ok(Self::ScrollToScreenMiddle), + "scroll-to-screen-bottom" => Ok(Self::ScrollToScreenBottom), - "accept" => Ok(Action::Accept), - "return-selection" => Ok(Action::ReturnSelection), - "copy" => Ok(Action::Copy), - "delete" => Ok(Action::Delete), - "delete-all" => Ok(Action::DeleteAll), - "return-original" => Ok(Action::ReturnOriginal), - "return-query" => Ok(Action::ReturnQuery), - "exit" => Ok(Action::Exit), - "redraw" => Ok(Action::Redraw), - "cycle-filter-mode" => Ok(Action::CycleFilterMode), - "cycle-search-mode" => Ok(Action::CycleSearchMode), - "switch-context" => Ok(Action::SwitchContext), - "clear-context" => Ok(Action::ClearContext), - "toggle-tab" => Ok(Action::ToggleTab), + "accept" => Ok(Self::Accept), + "return-selection" => Ok(Self::ReturnSelection), + "copy" => Ok(Self::Copy), + "delete" => Ok(Self::Delete), + "delete-all" => Ok(Self::DeleteAll), + "return-original" => Ok(Self::ReturnOriginal), + "return-query" => Ok(Self::ReturnQuery), + "exit" => Ok(Self::Exit), + "redraw" => Ok(Self::Redraw), + "cycle-filter-mode" => Ok(Self::CycleFilterMode), + "cycle-search-mode" => Ok(Self::CycleSearchMode), + "switch-context" => Ok(Self::SwitchContext), + "clear-context" => Ok(Self::ClearContext), + "toggle-tab" => Ok(Self::ToggleTab), - "vim-enter-normal" => Ok(Action::VimEnterNormal), - "vim-enter-insert" => Ok(Action::VimEnterInsert), - "vim-enter-insert-after" => Ok(Action::VimEnterInsertAfter), - "vim-enter-insert-at-start" => Ok(Action::VimEnterInsertAtStart), - "vim-enter-insert-at-end" => Ok(Action::VimEnterInsertAtEnd), - "vim-search-insert" => Ok(Action::VimSearchInsert), - "vim-change-to-end" => Ok(Action::VimChangeToEnd), - "enter-prefix-mode" => Ok(Action::EnterPrefixMode), + "vim-enter-normal" => Ok(Self::VimEnterNormal), + "vim-enter-insert" => Ok(Self::VimEnterInsert), + "vim-enter-insert-after" => Ok(Self::VimEnterInsertAfter), + "vim-enter-insert-at-start" => Ok(Self::VimEnterInsertAtStart), + "vim-enter-insert-at-end" => Ok(Self::VimEnterInsertAtEnd), + "vim-search-insert" => Ok(Self::VimSearchInsert), + "vim-change-to-end" => Ok(Self::VimChangeToEnd), + "enter-prefix-mode" => Ok(Self::EnterPrefixMode), - "inspect-previous" => Ok(Action::InspectPrevious), - "inspect-next" => Ok(Action::InspectNext), + "inspect-previous" => Ok(Self::InspectPrevious), + "inspect-next" => Ok(Self::InspectNext), - "noop" => Ok(Action::Noop), + "noop" => Ok(Self::Noop), _ => Err(format!("unknown action: {s}")), } @@ -158,65 +158,65 @@ impl Action { /// Convert to a kebab-case string. pub(crate) fn as_str(&self) -> String { match self { - Action::CursorLeft => "cursor-left".to_string(), - Action::CursorRight => "cursor-right".to_string(), - Action::CursorWordLeft => "cursor-word-left".to_string(), - Action::CursorWordRight => "cursor-word-right".to_string(), - Action::CursorWordEnd => "cursor-word-end".to_string(), - Action::CursorStart => "cursor-start".to_string(), - Action::CursorEnd => "cursor-end".to_string(), + Self::CursorLeft => "cursor-left".to_string(), + Self::CursorRight => "cursor-right".to_string(), + Self::CursorWordLeft => "cursor-word-left".to_string(), + Self::CursorWordRight => "cursor-word-right".to_string(), + Self::CursorWordEnd => "cursor-word-end".to_string(), + Self::CursorStart => "cursor-start".to_string(), + Self::CursorEnd => "cursor-end".to_string(), - Action::DeleteCharBefore => "delete-char-before".to_string(), - Action::DeleteCharAfter => "delete-char-after".to_string(), - Action::DeleteWordBefore => "delete-word-before".to_string(), - Action::DeleteWordAfter => "delete-word-after".to_string(), - Action::DeleteToWordBoundary => "delete-to-word-boundary".to_string(), - Action::ClearLine => "clear-line".to_string(), - Action::ClearToStart => "clear-to-start".to_string(), - Action::ClearToEnd => "clear-to-end".to_string(), + Self::DeleteCharBefore => "delete-char-before".to_string(), + Self::DeleteCharAfter => "delete-char-after".to_string(), + Self::DeleteWordBefore => "delete-word-before".to_string(), + Self::DeleteWordAfter => "delete-word-after".to_string(), + Self::DeleteToWordBoundary => "delete-to-word-boundary".to_string(), + Self::ClearLine => "clear-line".to_string(), + Self::ClearToStart => "clear-to-start".to_string(), + Self::ClearToEnd => "clear-to-end".to_string(), - Action::SelectNext => "select-next".to_string(), - Action::SelectPrevious => "select-previous".to_string(), - Action::ScrollHalfPageUp => "scroll-half-page-up".to_string(), - Action::ScrollHalfPageDown => "scroll-half-page-down".to_string(), - Action::ScrollPageUp => "scroll-page-up".to_string(), - Action::ScrollPageDown => "scroll-page-down".to_string(), - Action::ScrollToTop => "scroll-to-top".to_string(), - Action::ScrollToBottom => "scroll-to-bottom".to_string(), - Action::ScrollToScreenTop => "scroll-to-screen-top".to_string(), - Action::ScrollToScreenMiddle => "scroll-to-screen-middle".to_string(), - Action::ScrollToScreenBottom => "scroll-to-screen-bottom".to_string(), + Self::SelectNext => "select-next".to_string(), + Self::SelectPrevious => "select-previous".to_string(), + Self::ScrollHalfPageUp => "scroll-half-page-up".to_string(), + Self::ScrollHalfPageDown => "scroll-half-page-down".to_string(), + Self::ScrollPageUp => "scroll-page-up".to_string(), + Self::ScrollPageDown => "scroll-page-down".to_string(), + Self::ScrollToTop => "scroll-to-top".to_string(), + Self::ScrollToBottom => "scroll-to-bottom".to_string(), + Self::ScrollToScreenTop => "scroll-to-screen-top".to_string(), + Self::ScrollToScreenMiddle => "scroll-to-screen-middle".to_string(), + Self::ScrollToScreenBottom => "scroll-to-screen-bottom".to_string(), - Action::Accept => "accept".to_string(), - Action::AcceptNth(n) => format!("accept-{n}"), - Action::ReturnSelection => "return-selection".to_string(), - Action::ReturnSelectionNth(n) => format!("return-selection-{n}"), - Action::Copy => "copy".to_string(), - Action::Delete => "delete".to_string(), - Action::DeleteAll => "delete-all".to_string(), - Action::ReturnOriginal => "return-original".to_string(), - Action::ReturnQuery => "return-query".to_string(), - Action::Exit => "exit".to_string(), - Action::Redraw => "redraw".to_string(), - Action::CycleFilterMode => "cycle-filter-mode".to_string(), - Action::CycleSearchMode => "cycle-search-mode".to_string(), - Action::SwitchContext => "switch-context".to_string(), - Action::ClearContext => "clear-context".to_string(), - Action::ToggleTab => "toggle-tab".to_string(), + Self::Accept => "accept".to_string(), + Self::AcceptNth(n) => format!("accept-{n}"), + Self::ReturnSelection => "return-selection".to_string(), + Self::ReturnSelectionNth(n) => format!("return-selection-{n}"), + Self::Copy => "copy".to_string(), + Self::Delete => "delete".to_string(), + Self::DeleteAll => "delete-all".to_string(), + Self::ReturnOriginal => "return-original".to_string(), + Self::ReturnQuery => "return-query".to_string(), + Self::Exit => "exit".to_string(), + Self::Redraw => "redraw".to_string(), + Self::CycleFilterMode => "cycle-filter-mode".to_string(), + Self::CycleSearchMode => "cycle-search-mode".to_string(), + Self::SwitchContext => "switch-context".to_string(), + Self::ClearContext => "clear-context".to_string(), + Self::ToggleTab => "toggle-tab".to_string(), - Action::VimEnterNormal => "vim-enter-normal".to_string(), - Action::VimEnterInsert => "vim-enter-insert".to_string(), - Action::VimEnterInsertAfter => "vim-enter-insert-after".to_string(), - Action::VimEnterInsertAtStart => "vim-enter-insert-at-start".to_string(), - Action::VimEnterInsertAtEnd => "vim-enter-insert-at-end".to_string(), - Action::VimSearchInsert => "vim-search-insert".to_string(), - Action::VimChangeToEnd => "vim-change-to-end".to_string(), - Action::EnterPrefixMode => "enter-prefix-mode".to_string(), + Self::VimEnterNormal => "vim-enter-normal".to_string(), + Self::VimEnterInsert => "vim-enter-insert".to_string(), + Self::VimEnterInsertAfter => "vim-enter-insert-after".to_string(), + Self::VimEnterInsertAtStart => "vim-enter-insert-at-start".to_string(), + Self::VimEnterInsertAtEnd => "vim-enter-insert-at-end".to_string(), + Self::VimSearchInsert => "vim-search-insert".to_string(), + Self::VimChangeToEnd => "vim-change-to-end".to_string(), + Self::EnterPrefixMode => "enter-prefix-mode".to_string(), - Action::InspectPrevious => "inspect-previous".to_string(), - Action::InspectNext => "inspect-next".to_string(), + Self::InspectPrevious => "inspect-previous".to_string(), + Self::InspectNext => "inspect-next".to_string(), - Action::Noop => "noop".to_string(), + Self::Noop => "noop".to_string(), } } } @@ -236,7 +236,7 @@ impl Serialize for Action { impl<'de> Deserialize<'de> for Action { fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { let s = String::deserialize(deserializer)?; - Action::from_str(&s).map_err(serde::de::Error::custom) + Self::from_str(&s).map_err(serde::de::Error::custom) } } diff --git a/crates/turtle/src/command/client/search/keybindings/conditions.rs b/crates/turtle/src/command/client/search/keybindings/conditions.rs index f870d9a0..e52e4864 100644 --- a/crates/turtle/src/command/client/search/keybindings/conditions.rs +++ b/crates/turtle/src/command/client/search/keybindings/conditions.rs @@ -30,9 +30,9 @@ pub(crate) enum ConditionAtom { #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum ConditionExpr { Atom(ConditionAtom), - Not(Box<ConditionExpr>), - And(Box<ConditionExpr>, Box<ConditionExpr>), - Or(Box<ConditionExpr>, Box<ConditionExpr>), + Not(Box<Self>), + And(Box<Self>, Box<Self>), + Or(Box<Self>, Box<Self>), } /// Context needed to evaluate conditions. This is a pure snapshot of state — @@ -62,32 +62,32 @@ impl ConditionAtom { /// Evaluate this atom against the given context. pub(crate) fn evaluate(&self, ctx: &EvalContext) -> bool { match self { - ConditionAtom::CursorAtStart => ctx.cursor_position == 0, - ConditionAtom::CursorAtEnd => ctx.cursor_position == ctx.input_width, - ConditionAtom::InputEmpty => ctx.input_byte_len == 0, - ConditionAtom::OriginalInputEmpty => ctx.original_input_empty, - ConditionAtom::ListAtEnd => { + Self::CursorAtStart => ctx.cursor_position == 0, + Self::CursorAtEnd => ctx.cursor_position == ctx.input_width, + Self::InputEmpty => ctx.input_byte_len == 0, + Self::OriginalInputEmpty => ctx.original_input_empty, + Self::ListAtEnd => { ctx.results_len == 0 || ctx.selected_index >= ctx.results_len.saturating_sub(1) } - ConditionAtom::ListAtStart => ctx.results_len == 0 || ctx.selected_index == 0, - ConditionAtom::NoResults => ctx.results_len == 0, - ConditionAtom::HasResults => ctx.results_len > 0, - ConditionAtom::HasContext => ctx.has_context, + Self::ListAtStart => ctx.results_len == 0 || ctx.selected_index == 0, + Self::NoResults => ctx.results_len == 0, + Self::HasResults => ctx.results_len > 0, + Self::HasContext => ctx.has_context, } } /// Parse from a kebab-case string. pub(crate) fn from_str(s: &str) -> Result<Self, String> { match s { - "cursor-at-start" => Ok(ConditionAtom::CursorAtStart), - "cursor-at-end" => Ok(ConditionAtom::CursorAtEnd), - "input-empty" => Ok(ConditionAtom::InputEmpty), - "original-input-empty" => Ok(ConditionAtom::OriginalInputEmpty), - "list-at-end" => Ok(ConditionAtom::ListAtEnd), - "list-at-start" => Ok(ConditionAtom::ListAtStart), - "no-results" => Ok(ConditionAtom::NoResults), - "has-results" => Ok(ConditionAtom::HasResults), - "has-context" => Ok(ConditionAtom::HasContext), + "cursor-at-start" => Ok(Self::CursorAtStart), + "cursor-at-end" => Ok(Self::CursorAtEnd), + "input-empty" => Ok(Self::InputEmpty), + "original-input-empty" => Ok(Self::OriginalInputEmpty), + "list-at-end" => Ok(Self::ListAtEnd), + "list-at-start" => Ok(Self::ListAtStart), + "no-results" => Ok(Self::NoResults), + "has-results" => Ok(Self::HasResults), + "has-context" => Ok(Self::HasContext), _ => Err(format!("unknown condition: {s}")), } } @@ -95,15 +95,15 @@ impl ConditionAtom { /// Convert to a kebab-case string. pub(crate) fn as_str(&self) -> &'static str { match self { - ConditionAtom::CursorAtStart => "cursor-at-start", - ConditionAtom::CursorAtEnd => "cursor-at-end", - ConditionAtom::InputEmpty => "input-empty", - ConditionAtom::OriginalInputEmpty => "original-input-empty", - ConditionAtom::ListAtEnd => "list-at-end", - ConditionAtom::ListAtStart => "list-at-start", - ConditionAtom::NoResults => "no-results", - ConditionAtom::HasResults => "has-results", - ConditionAtom::HasContext => "has-context", + Self::CursorAtStart => "cursor-at-start", + Self::CursorAtEnd => "cursor-at-end", + Self::InputEmpty => "input-empty", + Self::OriginalInputEmpty => "original-input-empty", + Self::ListAtEnd => "list-at-end", + Self::ListAtStart => "list-at-start", + Self::NoResults => "no-results", + Self::HasResults => "has-results", + Self::HasContext => "has-context", } } } @@ -122,10 +122,10 @@ impl ConditionExpr { /// Evaluate this expression against the given context. pub(crate) fn evaluate(&self, ctx: &EvalContext) -> bool { match self { - ConditionExpr::Atom(atom) => atom.evaluate(ctx), - ConditionExpr::Not(inner) => !inner.evaluate(ctx), - ConditionExpr::And(lhs, rhs) => lhs.evaluate(ctx) && rhs.evaluate(ctx), - ConditionExpr::Or(lhs, rhs) => lhs.evaluate(ctx) || rhs.evaluate(ctx), + Self::Atom(atom) => atom.evaluate(ctx), + Self::Not(inner) => !inner.evaluate(ctx), + Self::And(lhs, rhs) => lhs.evaluate(ctx) && rhs.evaluate(ctx), + Self::Or(lhs, rhs) => lhs.evaluate(ctx) || rhs.evaluate(ctx), } } } @@ -136,7 +136,7 @@ impl ConditionExpr { impl From<ConditionAtom> for ConditionExpr { fn from(atom: ConditionAtom) -> Self { - ConditionExpr::Atom(atom) + Self::Atom(atom) } } @@ -144,17 +144,17 @@ impl From<ConditionAtom> for ConditionExpr { impl ConditionExpr { /// Negate this expression: `!self`. pub(crate) fn not(self) -> Self { - ConditionExpr::Not(Box::new(self)) + Self::Not(Box::new(self)) } /// Conjoin with another expression: `self && other`. - pub(crate) fn and(self, other: ConditionExpr) -> Self { - ConditionExpr::And(Box::new(self), Box::new(other)) + pub(crate) fn and(self, other: Self) -> Self { + Self::And(Box::new(self), Box::new(other)) } /// Disjoin with another expression: `self || other`. - pub(crate) fn or(self, other: ConditionExpr) -> Self { - ConditionExpr::Or(Box::new(self), Box::new(other)) + pub(crate) fn or(self, other: Self) -> Self { + Self::Or(Box::new(self), Box::new(other)) } } @@ -308,10 +308,10 @@ enum Prec { impl ConditionExpr { fn prec(&self) -> Prec { match self { - ConditionExpr::Or(..) => Prec::Or, - ConditionExpr::And(..) => Prec::And, - ConditionExpr::Not(..) => Prec::Not, - ConditionExpr::Atom(..) => Prec::Atom, + Self::Or(..) => Prec::Or, + Self::And(..) => Prec::And, + Self::Not(..) => Prec::Not, + Self::Atom(..) => Prec::Atom, } } @@ -321,17 +321,17 @@ impl ConditionExpr { write!(f, "(")?; } match self { - ConditionExpr::Atom(atom) => write!(f, "{atom}")?, - ConditionExpr::Not(inner) => { + Self::Atom(atom) => write!(f, "{atom}")?, + Self::Not(inner) => { write!(f, "!")?; inner.fmt_with_prec(f, Prec::Not)?; } - ConditionExpr::And(lhs, rhs) => { + Self::And(lhs, rhs) => { lhs.fmt_with_prec(f, Prec::And)?; write!(f, " && ")?; rhs.fmt_with_prec(f, Prec::And)?; } - ConditionExpr::Or(lhs, rhs) => { + Self::Or(lhs, rhs) => { lhs.fmt_with_prec(f, Prec::Or)?; write!(f, " || ")?; rhs.fmt_with_prec(f, Prec::Or)?; @@ -363,7 +363,7 @@ impl Serialize for ConditionExpr { impl<'de> Deserialize<'de> for ConditionExpr { fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { let s = String::deserialize(deserializer)?; - ConditionExpr::parse(&s).map_err(serde::de::Error::custom) + Self::parse(&s).map_err(serde::de::Error::custom) } } diff --git a/crates/turtle/src/command/client/search/keybindings/defaults.rs b/crates/turtle/src/command/client/search/keybindings/defaults.rs index 82219b33..4d00b475 100644 --- a/crates/turtle/src/command/client/search/keybindings/defaults.rs +++ b/crates/turtle/src/command/client/search/keybindings/defaults.rs @@ -477,7 +477,7 @@ fn apply_config_to_keymap(keymap: &mut Keymap, overrides: &HashMap<String, KeyBi impl KeymapSet { /// Build the complete set of default keymaps from settings. pub(crate) fn defaults(settings: &Settings) -> Self { - KeymapSet { + Self { emacs: default_emacs_keymap(settings), vim_normal: default_vim_normal_keymap(settings), vim_insert: default_vim_insert_keymap(settings), diff --git a/crates/turtle/src/command/client/search/keybindings/keymap.rs b/crates/turtle/src/command/client/search/keybindings/keymap.rs index c3b93b59..00678b20 100644 --- a/crates/turtle/src/command/client/search/keybindings/keymap.rs +++ b/crates/turtle/src/command/client/search/keybindings/keymap.rs @@ -28,7 +28,7 @@ pub(crate) struct Keymap { impl KeyRule { /// Create an unconditional rule. pub(crate) fn always(action: Action) -> Self { - KeyRule { + Self { condition: None, action, } @@ -37,7 +37,7 @@ impl KeyRule { /// Create a conditional rule. Accepts any type convertible to `ConditionExpr`, /// including bare `ConditionAtom` values. pub(crate) fn when(condition: impl Into<ConditionExpr>, action: Action) -> Self { - KeyRule { + Self { condition: Some(condition.into()), action, } @@ -47,21 +47,21 @@ impl KeyRule { impl KeyBinding { /// Create a simple (unconditional) binding. pub(crate) fn simple(action: Action) -> Self { - KeyBinding { + Self { rules: vec![KeyRule::always(action)], } } /// Create a conditional binding from a list of rules. pub(crate) fn conditional(rules: Vec<KeyRule>) -> Self { - KeyBinding { rules } + Self { rules } } } impl Keymap { /// Create an empty keymap. pub(crate) fn new() -> Self { - Keymap { + Self { bindings: HashMap::new(), } } @@ -101,7 +101,7 @@ impl Keymap { /// Merge another keymap into this one. Keys from `other` override keys in `self`. #[expect(dead_code)] - pub(crate) fn merge(&mut self, other: &Keymap) { + pub(crate) fn merge(&mut self, other: &Self) { for (key, binding) in &other.bindings { self.bindings.insert(key.clone(), binding.clone()); } diff --git a/crates/turtle/src/command/client/server.rs b/crates/turtle/src/command/client/server.rs index d821d6f8..88b12a7a 100644 --- a/crates/turtle/src/command/client/server.rs +++ b/crates/turtle/src/command/client/server.rs @@ -26,7 +26,7 @@ pub(crate) enum Cmd { impl Cmd { pub(crate) async fn run(self) -> Result<()> { match self { - Cmd::Start { host, port } => { + Self::Start { host, port } => { let settings = Settings::new().wrap_err("could not load server settings")?; let host = host.as_ref().unwrap_or(&settings.host).clone(); let port = port.unwrap_or(settings.port); @@ -46,7 +46,7 @@ impl Cmd { } } } - Cmd::DefaultConfig => { + Self::DefaultConfig => { // TODO(@bpeetz): Add this back <2026-06-11> println!("TODO"); Ok(()) diff --git a/crates/turtle/src/command/client/sync/status.rs b/crates/turtle/src/command/client/sync/status.rs index e75171eb..caf3b90f 100644 --- a/crates/turtle/src/command/client/sync/status.rs +++ b/crates/turtle/src/command/client/sync/status.rs @@ -16,7 +16,7 @@ pub(crate) async fn run(settings: &Settings) -> Result<()> { println!("{}", "[Remote]".green()); println!("Address: {}", settings.sync.address); - println!("User id: {}", me); + println!("User id: {me}"); } else { bail!("You are not logged in to a sync server - cannot show sync status"); } diff --git a/crates/turtle/src/command/gen_completions.rs b/crates/turtle/src/command/gen_completions.rs index 7cc697d4..9f13bffc 100644 --- a/crates/turtle/src/command/gen_completions.rs +++ b/crates/turtle/src/command/gen_completions.rs @@ -61,7 +61,7 @@ pub(crate) struct Cmd { impl Cmd { pub(crate) fn run(self) -> Result<()> { - let Cmd { shell, out_dir } = self; + let Self { shell, out_dir } = self; let mut cli = crate::Atuin::command(); |
