chore:: clippy

This commit is contained in:
Vukašin Vojinović 2026-04-27 13:18:15 +02:00 • committed by Michael Murphy
parent ec1b80534a
commit a7ca33b6eb
7 changed files with 120 additions and 121 deletions

View file

@ -19,8 +19,8 @@ pub struct UserFilter {
uid_max: u32,
}
impl UserFilter {
pub fn new() -> Self {
impl Default for UserFilter {
fn default() -> Self {
let login_defs_data = fs::read_to_string("/etc/login.defs").unwrap_or_default();
let login_defs = whitespace_conf::parse(&login_defs_data);
Self {
@ -34,6 +34,12 @@ impl UserFilter {
.unwrap_or(65000),
}
}
}
impl UserFilter {
pub fn new() -> Self {
Self::default()
}
pub fn filter(&self, user: &pwd::Passwd) -> bool {
if user.uid < self.uid_min || user.uid > self.uid_max {
@ -80,10 +86,10 @@ impl UserData {
})
});
for (_, source) in self.bg_state.wallpapers.iter() {
match source {
//TODO: do not reread duplicate paths, cache data by path?
BgSource::Path(path) => {
if !self.bg_path_data.contains_key(path) {
if let BgSource::Path(path) = source
&& !self.bg_path_data.contains_key(path)
{
match fs::read(path) {
Ok(bytes) => {
self.bg_path_data.insert(path.clone(), bytes);
@ -94,10 +100,6 @@ impl UserData {
}
}
}
// Other types not supported
_ => {}
}
}
}
pub fn load_config_as_user(&mut self) {

View file

@ -204,8 +204,9 @@ impl<M: From<Message> + Send + 'static> Common<M> {
self.update_wallpapers(user_data);
// From cosmic-applet-input-sources
if let Some(keyboard_layouts) = &self.layouts_opt {
if let Some(xkb_config) = &user_data.xkb_config_opt {
if let Some(keyboard_layouts) = &self.layouts_opt
&& let Some(xkb_config) = &user_data.xkb_config_opt
{
self.active_layouts.clear();
let config_layouts = xkb_config.layout.split_terminator(',');
let config_variants = xkb_config
@ -247,7 +248,6 @@ impl<M: From<Message> + Send + 'static> Common<M> {
tracing::info!("{:?}", self.active_layouts);
}
}
}
pub fn update(&mut self, message: Message) -> Task<M> {
match message {
@ -271,14 +271,14 @@ impl<M: From<Message> + Send + 'static> Common<M> {
&& !modifiers.alt()
&& matches!(key, Key::Character(_))
{
if let Some(text) = text {
if let Some((_, _, Some(value))) = &mut self.prompt_opt {
if let Some(text) = text
&& let Some((_, _, Some(value))) = &mut self.prompt_opt
{
value.push_str(&text);
}
}
if let Some(surface_id) = self.active_surface_id_opt {
if let Some(text_input_id) = self
if let Some(surface_id) = self.active_surface_id_opt
&& let Some(text_input_id) = self
.surface_names
.get(&surface_id)
.and_then(|id| self.text_input_ids.get(id))
@ -287,7 +287,6 @@ impl<M: From<Message> + Send + 'static> Common<M> {
}
}
}
}
Message::NetworkIcon(network_icon_opt) => {
self.network_icon_opt =
network_icon_opt.map(|name| widget::icon::from_name(name).into());
@ -306,9 +305,9 @@ impl<M: From<Message> + Send + 'static> Common<M> {
Message::Prompt(prompt, secret, value_opt) => {
let prompt_was_none = self.prompt_opt.is_none();
self.prompt_opt = Some((prompt, secret, value_opt));
if prompt_was_none {
if let Some(surface_id) = self.active_surface_id_opt {
if let Some(text_input_id) = self
if prompt_was_none
&& let Some(surface_id) = self.active_surface_id_opt
&& let Some(text_input_id) = self
.surface_names
.get(&surface_id)
.and_then(|id| self.text_input_ids.get(id))
@ -317,8 +316,6 @@ impl<M: From<Message> + Send + 'static> Common<M> {
return widget::text_input::focus(text_input_id.clone());
}
}
}
}
Message::SessionLockEvent(lock_event) => {
if let Some(on_session_lock_event) = &self.on_session_lock_event {
return Task::done(cosmic::Action::App(on_session_lock_event(lock_event)));

View file

@ -482,7 +482,7 @@ impl App {
.discard()
}
fn menu(&self, id: SurfaceId) -> Element<Message> {
fn menu(&self, id: SurfaceId) -> Element<'_, Message> {
let window_width = self
.common
.window_size
@ -1884,12 +1884,12 @@ impl cosmic::Application for App {
}
// Not used for layer surface window
fn view(&self) -> Element<Self::Message> {
fn view(&self) -> Element<'_, Self::Message> {
unimplemented!()
}
/// Creates a view after each update.
fn view_window(&self, surface_id: SurfaceId) -> Element<Self::Message> {
fn view_window(&self, surface_id: SurfaceId) -> Element<'_, Self::Message> {
let img = self
.common
.surface_images

View file

@ -325,7 +325,7 @@ pub struct App {
}
impl App {
fn menu(&self, surface_id: SurfaceId) -> Element<Message> {
fn menu(&self, surface_id: SurfaceId) -> Element<'_, Message> {
let window_width = self
.common
.window_size
@ -1132,11 +1132,11 @@ impl cosmic::Application for App {
}
self.spinner_rotation = 0.0;
// Try to create lockfile when locking
if let Some(ref lockfile) = self.flags.lockfile_opt {
if let Err(err) = fs::File::create(lockfile) {
if let Some(ref lockfile) = self.flags.lockfile_opt
&& let Err(err) = fs::File::create(lockfile)
{
tracing::warn!("failed to create lockfile {:?}: {}", lockfile, err);
}
}
// Tell compositor to lock
return lock();
}
@ -1165,11 +1165,11 @@ impl cosmic::Application for App {
}
self.spinner_rotation = 0.0;
// Try to delete lockfile when unlocking
if let Some(ref lockfile) = self.flags.lockfile_opt {
if let Err(err) = fs::remove_file(lockfile) {
if let Some(ref lockfile) = self.flags.lockfile_opt
&& let Err(err) = fs::remove_file(lockfile)
{
tracing::warn!("failed to remove lockfile {:?}: {}", lockfile, err);
}
}
// Destroy lock surfaces
let mut commands = Vec::with_capacity(self.common.surface_ids.len() + 1);
@ -1204,12 +1204,12 @@ impl cosmic::Application for App {
}
// Not used for layer surface window
fn view(&self) -> Element<Self::Message> {
fn view(&self) -> Element<'_, Self::Message> {
unimplemented!()
}
/// Creates a view after each update.
fn view_window(&self, surface_id: SurfaceId) -> Element<Self::Message> {
fn view_window(&self, surface_id: SurfaceId) -> Element<'_, Self::Message> {
let img = self
.common
.surface_images

View file

@ -77,8 +77,9 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<&'static str>>) -> Result<
};
}
Some(SpecificDevice::Wireless(wireless)) => {
if let Ok(ap) = wireless.active_access_point().await {
if let Ok(strength) = ap.strength().await {
if let Ok(ap) = wireless.active_access_point().await
&& let Ok(strength) = ap.strength().await
{
// Wireless always overrides with the highest strength
icon = match icon {
NetworkIcon::Wireless(other_strength) => {
@ -88,7 +89,6 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<&'static str>>) -> Result<
};
}
}
}
_ => {}
}
}

View file

@ -41,13 +41,13 @@ impl Time {
}
// Try language-only fallback (e.g., "en" from "en-US")
if let Some(lang) = cleaned_locale.split('-').next() {
if let Ok(locale) = Locale::try_from_str(lang) {
if let Some(lang) = cleaned_locale.split('-').next()
&& let Ok(locale) = Locale::try_from_str(lang)
{
return locale;
}
}
}
}
tracing::warn!("No valid locale found in environment, using fallback");
Locale::try_from_str("en-US").expect("Failed to parse fallback locale 'en-US'")
}
@ -72,7 +72,7 @@ impl Time {
.timezone
.as_ref()
.map(|tz| jiff::Timestamp::now().to_zoned(tz.clone()))
.unwrap_or_else(|| jiff::Zoned::now());
.unwrap_or_else(jiff::Zoned::now);
}
pub fn format_date(&self) -> String {

View file

@ -52,8 +52,9 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<(f64, bool, bool)>>) -> Re
loop {
let mut info_opt = None;
if let Ok(mut percent) = dev.percentage().await {
if let Ok(state) = dev.state().await {
if let Ok(mut percent) = dev.percentage().await
&& let Ok(state) = dev.state().await
{
let threshold_enabled = dev.charge_threshold_enabled().await.unwrap_or_default();
let mut capacity = dev.capacity().await.unwrap_or(100.);
if capacity <= 1. {
@ -72,7 +73,6 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Option<(f64, bool, bool)>>) -> Re
threshold_enabled,
));
}
}
msg_tx.send(info_opt).await.unwrap();