From a51cfde28bd1664b55ea31686ac1def018fc0bd7 Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 29 Nov 2024 09:26:39 +0800 Subject: chore: clippy for the new rust version (#1018) --- src/client/macros.rs | 13 ++++++------- src/render/stream.rs | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/client/macros.rs b/src/client/macros.rs index ee710c3..0543cd6 100644 --- a/src/client/macros.rs +++ b/src/client/macros.rs @@ -98,21 +98,20 @@ macro_rules! register_client { anyhow::bail!("Unknown client '{}'", client) } - static mut ALL_CLIENT_MODELS: Option> = None; + static ALL_CLIENT_MODELS: std::sync::OnceLock> = std::sync::OnceLock::new(); pub fn list_models(config: &$crate::config::Config) -> Vec<&'static $crate::client::Model> { - if unsafe { ALL_CLIENT_MODELS.is_none() } { - let models: Vec<_> = config + let models = ALL_CLIENT_MODELS.get_or_init(|| { + config .clients .iter() .flat_map(|v| match v { $(ClientConfig::$config(c) => $client::list_models(c),)+ ClientConfig::Unknown => vec![], }) - .collect(); - unsafe { ALL_CLIENT_MODELS = Some(models) }; - } - unsafe { ALL_CLIENT_MODELS.as_ref().unwrap().iter().collect() } + .collect() + }); + models.iter().collect() } pub fn list_chat_models(config: &$crate::config::Config) -> Vec<&'static $crate::client::Model> { diff --git a/src/render/stream.rs b/src/render/stream.rs index 6ff6ea7..d2ac6ef 100644 --- a/src/render/stream.rs +++ b/src/render/stream.rs @@ -204,5 +204,5 @@ fn split_line_tail(text: &str) -> (&str, &str) { fn need_rows(text: &str, columns: u16) -> u16 { let buffer_width = display_width(text).max(1) as u16; - (buffer_width + columns - 1) / columns + buffer_width.div_ceil(columns) } -- cgit v1.2.3