Skip to content

Commit

Permalink
format rust
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 7, 2023
1 parent e3b6946 commit a9f6e25
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions rust/agama-lib/src/install_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//!
//! This module implements the mechanisms to load and store the installation settings.
use crate::{
network::NetworkSettings, software::SoftwareSettings, storage::StorageSettings,
users::UserSettings, product::ProductSettings
network::NetworkSettings, product::ProductSettings, software::SoftwareSettings,
storage::StorageSettings, users::UserSettings,
};
use agama_settings::Settings;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub mod error;
pub mod install_settings;
pub mod manager;
pub mod network;
pub mod profile;
pub mod product;
pub mod profile;
pub mod software;
pub mod storage;
pub mod users;
Expand Down
16 changes: 9 additions & 7 deletions rust/agama-lib/src/product/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use crate::software::proxies::SoftwareProductProxy;
use crate::error::ServiceError;
use crate::software::proxies::SoftwareProductProxy;
use serde::Serialize;
use zbus::Connection;

Expand All @@ -21,14 +21,14 @@ pub struct Product {
/// D-Bus client for the software service
pub struct ProductClient<'a> {
product_proxy: SoftwareProductProxy<'a>,
registration_proxy: RegistrationProxy<'a>
registration_proxy: RegistrationProxy<'a>,
}

impl<'a> ProductClient<'a> {
pub async fn new(connection: Connection) -> Result<ProductClient<'a>, ServiceError> {
Ok(Self {
product_proxy: SoftwareProductProxy::new(&connection).await?,
registration_proxy: RegistrationProxy::new(&connection).await?
registration_proxy: RegistrationProxy::new(&connection).await?,
})
}

Expand Down Expand Up @@ -76,19 +76,21 @@ impl<'a> ProductClient<'a> {
}

/// registration code used to register product
pub async fn registration_code(&self) -> Result<String, ServiceError>{
pub async fn registration_code(&self) -> Result<String, ServiceError> {
Ok(self.registration_proxy.reg_code().await?)
}

/// email used to register product
pub async fn email(&self) -> Result<String, ServiceError>{
pub async fn email(&self) -> Result<String, ServiceError> {
Ok(self.registration_proxy.email().await?)
}

/// register product
pub async fn register(&self, code :&str, _email: &str) -> Result<(), ServiceError> {
pub async fn register(&self, code: &str, _email: &str) -> Result<(), ServiceError> {
// TODO: handle email
self.registration_proxy.register(code, HashMap::new()).await?;
self.registration_proxy
.register(code, HashMap::new())
.await?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion rust/agama-lib/src/product/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ pub struct ProductSettings {
/// ID of the product to install (e.g., "ALP", "Tumbleweed", etc.)
pub id: Option<String>,
pub registration_code: Option<String>,
pub email: Option<String>
pub email: Option<String>,
}
2 changes: 1 addition & 1 deletion rust/agama-lib/src/product/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> ProductStore<'a> {
Ok(ProductSettings {
id: Some(product),
registration_code: Some(registration_code),
email: Some(email)
email: Some(email),
})
}

Expand Down
24 changes: 11 additions & 13 deletions rust/agama-lib/src/software/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Pattern {
/// Pattern summary
pub summary: String,
/// Pattern order
pub order: String
pub order: String,
}

/// D-Bus client for the software service
Expand All @@ -39,16 +39,16 @@ impl<'a> SoftwareClient<'a> {
.list_patterns(filtered)
.await?
.into_iter()
.map(|(id, (category, description, icon, summary, order))| {
Pattern {
.map(
|(id, (category, description, icon, summary, order))| Pattern {
id,
category,
icon,
description,
summary,
order
}
})
order,
},
)
.collect();
Ok(patterns)
}
Expand All @@ -61,20 +61,18 @@ impl<'a> SoftwareClient<'a> {
.selected_patterns()
.await?
.into_iter()
.filter(|(_id, reason)| {
*reason == USER_SELECTED
})
.map(|(id, _reason)| {
id
})
.filter(|(_id, reason)| *reason == USER_SELECTED)
.map(|(id, _reason)| id)
.collect();
Ok(patterns)
}

/// Selects patterns by user
pub async fn select_patterns(&self, patterns: &Vec<String>) -> Result<(), ServiceError> {
let patterns: Vec<&str> = patterns.iter().map(AsRef::as_ref).collect();
self.software_proxy.set_user_patterns(patterns.as_slice()).await?;
self.software_proxy
.set_user_patterns(patterns.as_slice())
.await?;
Ok(())
}
}
8 changes: 4 additions & 4 deletions rust/agama-lib/src/software/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ impl<'a> SoftwareStore<'a> {

pub async fn load(&self) -> Result<SoftwareSettings, ServiceError> {
let patterns = self.software_client.user_selected_patterns().await?;
Ok(SoftwareSettings {
patterns,
})
Ok(SoftwareSettings { patterns })
}

pub async fn store(&self, settings: &SoftwareSettings) -> Result<(), ServiceError> {
self.software_client.select_patterns(&settings.patterns).await?;
self.software_client
.select_patterns(&settings.patterns)
.await?;

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion rust/agama-lib/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use crate::error::ServiceError;
use crate::install_settings::{InstallSettings, Scope};
use crate::{
network::NetworkStore, software::SoftwareStore, storage::StorageStore, users::UsersStore, product::ProductStore
network::NetworkStore, product::ProductStore, software::SoftwareStore, storage::StorageStore,
users::UsersStore,
};
use zbus::Connection;

Expand Down

0 comments on commit a9f6e25

Please sign in to comment.