Modifica la identificación de módulos
This commit is contained in:
parent
0f185887a6
commit
9e65f89d2d
14 changed files with 46 additions and 48 deletions
|
|
@ -1,10 +1,10 @@
|
|||
use crate::core::server;
|
||||
use crate::core::{all, server};
|
||||
|
||||
/// Los módulos deben implementar este *trait*.
|
||||
pub trait Module: Send + Sync {
|
||||
fn id(&self) -> &'static str;
|
||||
fn name(&self) -> &'static str;
|
||||
|
||||
fn name(&self) -> String;
|
||||
fn fullname(&self) -> String;
|
||||
|
||||
fn description(&self) -> String {
|
||||
"".to_string()
|
||||
|
|
@ -14,3 +14,15 @@ pub trait Module: Send + Sync {
|
|||
fn configure_module(&self, cfg: &mut server::web::ServiceConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_module(m: &'static (dyn Module + 'static)) {
|
||||
all::MODULES.write().unwrap().push(m);
|
||||
}
|
||||
|
||||
pub fn find_module(name: &str) -> Option<&'static (dyn Module + 'static)> {
|
||||
let modules = all::MODULES.write().unwrap();
|
||||
match modules.iter().find(|t| t.name() == name) {
|
||||
Some(module) => Some(*module),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue