Skip to content

Commit

Permalink
chore(shared): remove name from module (#137)
Browse files Browse the repository at this point in the history
* chore: remove name from `module`

* fix broken tests
  • Loading branch information
elcharitas authored Aug 12, 2024
1 parent b5c9068 commit 1f00c03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 0 additions & 3 deletions crates/macros/src/core/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ pub(crate) fn module_macro(args: TokenStream, input: TokenStream) -> TokenStream
fn new() -> Self {
#init_module
}
fn name(&self) -> &str {
stringify!(#ident)
}
fn get_controllers(&self) -> Vec<std::sync::Arc<Box<dyn ngyn::shared::traits::NgynController + 'static>>> {
use ngyn::shared::traits::NgynInjectable;
let mut controllers: Vec<std::sync::Arc<Box<dyn ngyn::shared::traits::NgynController + 'static>>> = vec![#(#add_controllers),*];
Expand Down
22 changes: 17 additions & 5 deletions crates/shared/src/traits/module_trait.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
use crate::traits::NgynController;
use std::sync::Arc;

/// `NgynModule` is a trait that defines the basic structure of a module in Ngyn.
/// Modules are the building blocks of an application in Ngyn.
/// They are used to group related [controllers](https://ngyn.rs/docs/foundations/controllers).
///
/// ### Example
///
/// ```rust
/// use ngyn_shared::traits::NgynModule;
///
/// pub struct AppModule;
///
/// impl NgynModule for AppModule {
/// fn new() -> Self {
/// Self {}
/// }
/// }
/// ```
pub trait NgynModule: Send + Sync {
/// Creates a new instance of the module.
fn new() -> Self
where
Self: Sized;

/// Returns the name of the module.
fn name(&self) -> &str;

/// Returns the controllers of the module.
fn get_controllers(&self) -> Vec<Arc<Box<dyn NgynController + 'static>>> {
vec![]
Vec::new()
}
}

0 comments on commit 1f00c03

Please sign in to comment.