🏷️ {Trait}Base for Action/Module Component-like

This commit is contained in:
Manuel Cillero 2023-07-19 19:25:43 +02:00
parent 0a95f3d51c
commit 4ce59d6520
4 changed files with 8 additions and 8 deletions

View file

@ -1,5 +1,5 @@
mod definition;
pub use definition::{action_ref, ActionTrait, BaseAction};
pub use definition::{action_ref, ActionBase, ActionTrait};
mod list;
pub use list::Action;

View file

@ -2,11 +2,11 @@ use crate::{Handle, Weight};
use std::any::Any;
pub trait BaseAction: Any {
pub trait ActionBase: Any {
fn as_ref_any(&self) -> &dyn Any;
}
pub trait ActionTrait: BaseAction + Send + Sync {
pub trait ActionTrait: ActionBase + Send + Sync {
fn new() -> Self
where
Self: Sized;
@ -18,7 +18,7 @@ pub trait ActionTrait: BaseAction + Send + Sync {
}
}
impl<C: ActionTrait> BaseAction for C {
impl<C: ActionTrait> ActionBase for C {
fn as_ref_any(&self) -> &dyn Any {
self
}

View file

@ -1,4 +1,4 @@
mod definition;
pub use definition::{BaseModule, ModuleStaticRef, ModuleTrait};
pub use definition::{ModuleBase, ModuleStaticRef, ModuleTrait};
pub(crate) mod all;

View file

@ -8,12 +8,12 @@ use crate::db::MigrationItem;
pub type ModuleStaticRef = &'static dyn ModuleTrait;
pub trait BaseModule {
pub trait ModuleBase {
fn single_name(&self) -> &'static str;
}
/// Los módulos deben implementar este *trait*.
pub trait ModuleTrait: BaseModule + Send + Sync {
pub trait ModuleTrait: ModuleBase + Send + Sync {
fn handle(&self) -> Handle;
fn name(&self) -> L10n {
@ -52,7 +52,7 @@ pub trait ModuleTrait: BaseModule + Send + Sync {
fn configure_service(&self, cfg: &mut service::web::ServiceConfig) {}
}
impl<M: ?Sized + ModuleTrait> BaseModule for M {
impl<M: ?Sized + ModuleTrait> ModuleBase for M {
fn single_name(&self) -> &'static str {
util::single_type_name::<Self>()
}