Actualiza y revisa código aplicando cargo clippy

This commit is contained in:
Manuel Cillero 2022-07-20 00:53:00 +02:00
parent e6ea59785e
commit f3d57eb0aa
23 changed files with 45 additions and 53 deletions

View file

@ -51,7 +51,7 @@ fn form_login() -> Form {
Form::new()
.with_id("user-login")
.with_element(
form::Input::textfield()
form_element::Input::textfield()
.with_name("name")
.with_label(l("username").as_str())
.with_help_text(
@ -66,10 +66,10 @@ fn form_login() -> Form {
.with_autofocus(true),
)
.with_element(
form::Input::password()
form_element::Input::password()
.with_name("pass")
.with_label(l("password").as_str())
.with_help_text(l("password_help").as_str()),
)
.with_element(form::Button::submit(l("login").as_str()))
.with_element(form_element::Button::submit(l("login").as_str()))
}

View file

@ -17,8 +17,8 @@ pub static FIGFONT: Lazy<FIGfont> = Lazy::new(|| {
"starwars" => starwars,
_ => {
println!(
"\n FIGfont \"{}\" not found for banner. {}. {}.",
SETTINGS.app.startup_banner, "Using \"Slant\"", "Check the settings file",
"\n FIGfont \"{}\" not found for banner. Using \"Slant\". Check the settings file.",
SETTINGS.app.startup_banner,
);
slant
}

View file

@ -25,11 +25,11 @@ pub static DBCONN: Lazy<DbConn> = Lazy::new(|| {
)
.unwrap();
tmp_uri
.set_username(&SETTINGS.database.db_user.as_str())
.set_username(SETTINGS.database.db_user.as_str())
.unwrap();
// https://github.com/launchbadge/sqlx/issues/1624
tmp_uri
.set_password(Some(&SETTINGS.database.db_pass.as_str()))
.set_password(Some(SETTINGS.database.db_pass.as_str()))
.unwrap();
if SETTINGS.database.db_port != 0 {
tmp_uri.set_port(Some(SETTINGS.database.db_port)).unwrap();
@ -56,7 +56,7 @@ pub static DBCONN: Lazy<DbConn> = Lazy::new(|| {
run_now(Database::connect::<ConnectOptions>({
let mut db_opt = ConnectOptions::new(db_uri.to_string());
db_opt.max_connections(SETTINGS.database.max_pool_size);
db_opt.into()
db_opt
}))
.expect_or_log("Failed to connect to database")
});

View file

@ -18,7 +18,7 @@ use tracing_subscriber::EnvFilter;
/// enviarán antes de terminar la ejecución.
pub static TRACING: Lazy<WorkerGuard> = Lazy::new(|| {
let env_filter = EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or(EnvFilter::new("Info"));
let env_filter = EnvFilter::try_new(&SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info"));
let rolling = SETTINGS.log.rolling.to_lowercase();
let (non_blocking, guard) = match rolling.as_str() {
@ -33,8 +33,8 @@ pub static TRACING: Lazy<WorkerGuard> = Lazy::new(|| {
"endless" => tracing_appender::rolling::never(path, prefix),
_ => {
println!(
"Rolling value \"{}\" not valid. {}. {}.",
SETTINGS.log.rolling, "Using \"daily\"", "Check the settings file",
"Rolling value \"{}\" not valid. Using \"daily\". Check the settings file.",
SETTINGS.log.rolling,
);
tracing_appender::rolling::daily(path, prefix)
}
@ -52,8 +52,8 @@ pub static TRACING: Lazy<WorkerGuard> = Lazy::new(|| {
"pretty" => subscriber.pretty().init(),
_ => {
println!(
"Tracing format \"{}\" not valid. {}. {}.",
SETTINGS.log.format, "Using \"Full\"", "Check the settings file",
"Tracing format \"{}\" not valid. Using \"Full\". Check the settings file.",
SETTINGS.log.format,
);
subscriber.init();
}

View file

@ -20,5 +20,5 @@ pub use image::{Image, COMPONENT_IMAGE};
mod menu;
pub use menu::{Menu, MenuItem, MenuItemType, COMPONENT_MENU, COMPONENT_MENUITEM};
pub mod form;
pub use form::{Form, FormMethod, COMPONENT_FORM};
pub mod form_element;
pub use form_element::{Form, FormMethod, COMPONENT_FORM};

View file

@ -54,10 +54,7 @@ impl ComponentTrait for Button {
ButtonType::Reset => "reset",
ButtonType::Submit => "submit",
};
let id = match self.name().get() {
Some(name) => Some(concat_string!("edit-", name)),
_ => None,
};
let id = self.name().get().map(|name| concat_string!("edit-", name));
html! {
button
type=(button_type)
@ -86,7 +83,7 @@ impl ComponentTrait for Button {
}
impl Button {
pub fn button(value: &str) -> Self {
pub fn new_with_value(value: &str) -> Self {
Button::new().with_value(value)
}

View file

@ -53,10 +53,7 @@ impl ComponentTrait for Date {
}
fn default_render(&self, _: &mut InContext) -> Markup {
let id = match self.name().get() {
Some(name) => Some(concat_string!("edit-", name)),
None => None,
};
let id = self.name().get().map(|name| concat_string!("edit-", name));
html! {
div class=[self.classes().get()] {
@match self.label().get() {

View file

@ -26,10 +26,7 @@ impl ComponentTrait for Hidden {
}
fn default_render(&self, _: &mut InContext) -> Markup {
let id = match self.name().get() {
Some(name) => Some(concat_string!("value-", name)),
_ => None,
};
let id = self.name().get().map(|name| concat_string!("value-", name));
html! {
input type="hidden" id=[id] name=[self.name().get()] value=[self.value().get()];
}

View file

@ -78,10 +78,7 @@ impl ComponentTrait for Input {
InputType::Textfield => "text",
InputType::Url => "url",
};
let id = match self.name().get() {
Some(name) => Some(concat_string!("edit-", name)),
None => None,
};
let id = self.name().get().map(|name| concat_string!("edit-", name));
html! {
div class=[self.classes().get()] {
@match self.label().get() {

View file

@ -54,7 +54,7 @@ impl ComponentTrait for Image {
}
impl Image {
pub fn image(source: &str) -> Self {
pub fn new_with_source(source: &str) -> Self {
Image::new().with_source(source)
}

View file

@ -87,7 +87,7 @@ fn hello_world() -> Container {
.with_column(
grid::Column::new()
.with_classes(ClassesOp::Add, "hello-col-image")
.with_component(Image::image("/theme/images/demo-header.svg")),
.with_component(Image::new_with_source("/theme/images/demo-header.svg")),
),
)
}
@ -121,7 +121,7 @@ fn about_pagetop() -> Container {
grid::Column::new()
.with_classes(ClassesOp::Add, "pagetop-col-image")
.with_size(grid::ColumnSize::Is5of12)
.with_component(Image::image("/theme/images/demo-about.svg")),
.with_component(Image::new_with_source("/theme/images/demo-about.svg")),
)
.with_column(
grid::Column::new()
@ -152,7 +152,7 @@ fn promo_pagetop() -> Container {
grid::Column::new()
.with_classes(ClassesOp::Add, "promo-col-image")
.with_size(grid::ColumnSize::Is5of12)
.with_component(Image::image("/theme/images/demo-pagetop.svg")),
.with_component(Image::new_with_source("/theme/images/demo-pagetop.svg")),
)
.with_column(
grid::Column::new()
@ -195,7 +195,7 @@ fn reporting_problems() -> Container {
.with_column(
grid::Column::new()
.with_classes(ClassesOp::Add, "reporting-col-image")
.with_component(Image::image("/theme/images/demo-pagetop.svg")),
.with_component(Image::new_with_source("/theme/images/demo-pagetop.svg")),
),
)
}

View file

@ -6,7 +6,7 @@ use serde::Deserialize;
use std::env;
/// Nombre del directorio donde se encuentra la configuración.
const CONFIG_DIR: &'static str = "config";
const CONFIG_DIR: &str = "config";
/// Al arrancar la aplicación, carga los valores originales "clave = valor" de
/// los archivos de configuración. Con [`config_map`] se asignarán los ajustes
@ -15,7 +15,7 @@ const CONFIG_DIR: &'static str = "config";
pub static CONFIG: Lazy<Config> = Lazy::new(|| {
// Establece el modo de ejecución según el valor de la variable de entorno
// PAGETOP_RUN_MODE. Asume "default" por defecto.
let run_mode = env::var("PAGETOP_RUN_MODE").unwrap_or("default".into());
let run_mode = env::var("PAGETOP_RUN_MODE").unwrap_or_else(|_| "default".into());
// Inicializa los ajustes.
let mut settings = Config::default();

View file

@ -3,7 +3,7 @@ use crate::html::{html, Markup};
use std::sync::{Arc, RwLock};
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct ComponentsBundle(Vec<Arc<RwLock<dyn ComponentTrait>>>);
impl ComponentsBundle {

View file

@ -100,11 +100,11 @@ impl InContext {
pub fn required_id<T>(&mut self, id: &IdentifierValue) -> String {
match id.get() {
Some(id) => id.to_string(),
Some(id) => id,
None => {
let prefix = util::single_type_name::<T>()
.trim()
.replace(" ", "_")
.replace(' ', "_")
.to_lowercase();
let prefix = if prefix.is_empty() {
"prefix".to_owned()

View file

@ -33,17 +33,15 @@ fn add_to(list: &mut Vec<&dyn ModuleTrait>, module: &'static dyn ModuleTrait) {
.read()
.unwrap()
.iter()
.any(|m| m.handler() == module.handler())
.any(|m| m.handler() == module.handler()) && !list.iter().any(|m| m.handler() == module.handler())
{
if !list.iter().any(|m| m.handler() == module.handler()) {
trace::debug!("Enabling module \"{}\"", module.single_name());
list.push(module);
trace::debug!("Enabling module \"{}\"", module.single_name());
list.push(module);
let mut dependencies = module.dependencies();
dependencies.reverse();
for d in dependencies.iter() {
add_to(list, *d);
}
let mut dependencies = module.dependencies();
dependencies.reverse();
for d in dependencies.iter() {
add_to(list, *d);
}
}
}

View file

@ -13,7 +13,7 @@ macro_rules! pub_migration {
impl MigrationName for $migration {
fn name(&self) -> &str {
crate::util::partial_type_name(module_path!(), 1)
$crate::util::partial_type_name(module_path!(), 1)
}
}
};

View file

@ -17,6 +17,8 @@ pub enum AssetsOp<T: AssetsTrait> {
Add(T),
Remove(SourceValue),
}
#[derive(Default)]
pub struct Assets<T>(Vec<T>);
impl<T: AssetsTrait> Assets<T> {

View file

@ -1,3 +1,4 @@
#[derive(Default)]
pub struct AttributeValue(String);
impl AttributeValue {

View file

@ -14,6 +14,7 @@ pub enum ClassesOp {
SetDefaultIfEmpty,
}
#[derive(Default)]
pub struct Classes {
default: String,
added : String,

View file

@ -1,5 +1,6 @@
use crate::html::{html, Markup, PreEscaped};
#[derive(Default)]
pub struct Favicon(Vec<String>);
impl Favicon {

View file

@ -1,3 +1,4 @@
#[derive(Default)]
pub struct IdentifierValue(String);
impl IdentifierValue {
@ -12,7 +13,7 @@ impl IdentifierValue {
}
pub fn with_value(&mut self, value: &str) -> &Self {
self.0 = value.trim().replace(" ", "_");
self.0 = value.trim().replace(' ', "_");
self
}