diff --git a/src/service/function/service.rs b/src/service/function/service.rs index 1bcd7a34..5221a9ab 100644 --- a/src/service/function/service.rs +++ b/src/service/function/service.rs @@ -11,80 +11,79 @@ use typed_builder::TypedBuilder; /// A generic [AppService] to allow creating a service from an async function. /// /// # Examples -/// -/// ```rust -/// # use async_trait::async_trait; -/// # use clap::Parser; -/// # use sea_orm_migration::{MigrationTrait, MigratorTrait}; -/// use tokio_util::sync::CancellationToken; -/// # use roadster::api::cli::RunCommand; -/// use roadster::app_context::AppContext; -/// use roadster::error::RoadsterResult; -/// use roadster::service::function::service::FunctionService; -/// use roadster::service::registry::ServiceRegistry; -/// use roadster::app::App as RoadsterApp; -/// # -/// # #[derive(Debug, Parser)] -/// # #[command(version, about)] -/// # pub struct AppCli {} -/// # -/// # -/// # #[async_trait] -/// # impl RunCommand for AppCli { -/// # #[allow(clippy::disallowed_types)] -/// # async fn run( -/// # &self, -/// # _app: &App, -/// # _cli: &AppCli, -/// # _context: &AppContext<()>, -/// # ) -> RoadsterResult { -/// # Ok(false) -/// # } -/// # } -/// # pub struct Migrator; -/// # -/// # #[async_trait::async_trait] -/// # impl MigratorTrait for Migrator { -/// # fn migrations() -> Vec> { -/// # Default::default() -/// # } -/// # } -/// -/// async fn example_service( -/// _state: AppContext<()>, -/// _cancel_token: CancellationToken, -/// ) -> RoadsterResult<()> { -/// // Service logic here -/// Ok(()) -/// } -/// -/// pub struct App; -/// -/// #[async_trait] -/// impl RoadsterApp for App { -/// # type State = (); -/// # type Cli = AppCli; -/// # type M = Migrator; -/// # -/// # async fn with_state(_context: &AppContext) -> RoadsterResult { -/// # Ok(()) -/// # } -/// -/// async fn services( -/// registry: &mut ServiceRegistry, -/// context: &AppContext, -/// ) -> RoadsterResult<()> { -/// let service = FunctionService::builder() -/// .name("example".to_string()) -/// .enabled(true) -/// .function(example_service) -/// .build(); -/// registry.register_service(service)?; -/// Ok(()) -/// } -/// -/// } -/// ``` +#[cfg_attr( + feature = "default", + doc = r##" +```rust +# use async_trait::async_trait; +# use clap::Parser; +# use sea_orm_migration::{MigrationTrait, MigratorTrait}; +use tokio_util::sync::CancellationToken; +# use roadster::api::cli::RunCommand; +use roadster::app_context::AppContext; +use roadster::error::RoadsterResult; +use roadster::service::function::service::FunctionService; +use roadster::service::registry::ServiceRegistry; +use roadster::app::App as RoadsterApp; +# +# #[derive(Debug, Parser)] +# #[command(version, about)] +# pub struct AppCli {} +# +# +# #[async_trait] +# impl RunCommand for AppCli { +# #[allow(clippy::disallowed_types)] +# async fn run( +# &self, +# _app: &App, +# _cli: &AppCli, +# _context: &AppContext<()>, +# ) -> RoadsterResult { +# Ok(false) +# } +# } +# pub struct Migrator; +# +# #[async_trait::async_trait] +# impl MigratorTrait for Migrator { +# fn migrations() -> Vec> { +# Default::default() +# } +# } +async fn example_service( + _state: AppContext<()>, + _cancel_token: CancellationToken, +) -> RoadsterResult<()> { + // Service logic here + Ok(()) +} +pub struct App; +#[async_trait] +impl RoadsterApp for App { +# type State = (); +# type Cli = AppCli; +# type M = Migrator; +# +# async fn with_state(_context: &AppContext) -> RoadsterResult { +# Ok(()) +# } + async fn services( + registry: &mut ServiceRegistry, + context: &AppContext, + ) -> RoadsterResult<()> { + let service = FunctionService::builder() + .name("example".to_string()) + .enabled(true) + .function(example_service) + .build(); + registry.register_service(service)?; + Ok(()) + } +} +``` +"## +)] #[derive(TypedBuilder)] pub struct FunctionService where