Skip to content

Commit 8f4cf56

Browse files
authored
refactor: move example feature to the examples folder (#8)
- Also adding a function new created by the impl_feature_public_api macro for features.
1 parent e80e786 commit 8f4cf56

File tree

8 files changed

+26
-19
lines changed

8 files changed

+26
-19
lines changed

examples/apps/cronjob_service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
async-trait = "0.1.83"
8+
example = { path = "../../features/example" }
89
mikros = { path = "../../../" }
910
cronjob = { path = "../../services/cronjob" }
1011
simple_api = { path = "../../features/simple_api" }

examples/apps/cronjob_service/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async fn main() {
2525

2626
let svc = ServiceBuilder::default()
2727
.custom(c)
28-
.with_features(simple_api::features())
28+
.with_features(vec![simple_api::new(), example::new()])
2929
.build();
3030

3131
match svc {

examples/features/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"example",
5+
"simple_api"
6+
]

examples/features/example/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "example"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
async-trait = "0.1.83"
8+
mikros = { path = "../../../" }
9+
serde = "1.0.215"

src/features/example/mod.rs renamed to examples/features/example/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use std::sync::Arc;
44

55
use logger::fields::FieldValue;
66

7-
use crate::definition::Definitions;
8-
use crate::env::Env;
9-
use crate::{errors as merrors, impl_feature_public_api};
10-
use crate::plugin;
11-
use crate::service::context::Context;
7+
use mikros::definition::Definitions;
8+
use mikros::env::Env;
9+
use mikros::{errors as merrors, impl_feature_public_api};
10+
use mikros::{plugin, logger};
11+
use mikros::service::context::Context;
1212

1313
/// The feature public API.
1414
pub trait ExampleAPI {

examples/features/simple_api/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ pub trait ExampleAPI {
1414
fn do_something(&self);
1515
}
1616

17-
pub fn features() -> Vec<Box<dyn plugin::feature::Feature>> {
18-
vec![Box::new(Example::default())]
19-
}
20-
2117
#[derive(Clone, Default)]
2218
pub(crate) struct Example {
2319
definitions: Definitions

src/features/mod.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/plugin/feature.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ impl Clone for Box<dyn Feature> {
9797
#[macro_export]
9898
macro_rules! impl_feature_public_api {
9999
($api_trait:ident, $api_struct:ident, $feature_name:expr) => {
100+
pub fn new() -> Box<dyn mikros::plugin::feature::Feature> {
101+
Box::new($api_struct::default())
102+
}
103+
100104
pub async fn execute_on<F>(
101105
ctx: &Context,
102106
f: F,

0 commit comments

Comments
 (0)