Skip to content

Commit

Permalink
Update FunctionService doctest to only run with default features
Browse files Browse the repository at this point in the history
  • Loading branch information
spencewenski committed Jun 7, 2024
1 parent 236b9b2 commit e899d2d
Showing 1 changed file with 73 additions and 74 deletions.
147 changes: 73 additions & 74 deletions src/service/function/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<App> for AppCli {
/// # #[allow(clippy::disallowed_types)]
/// # async fn run(
/// # &self,
/// # _app: &App,
/// # _cli: &AppCli,
/// # _context: &AppContext<()>,
/// # ) -> RoadsterResult<bool> {
/// # Ok(false)
/// # }
/// # }
/// # pub struct Migrator;
/// #
/// # #[async_trait::async_trait]
/// # impl MigratorTrait for Migrator {
/// # fn migrations() -> Vec<Box<dyn MigrationTrait>> {
/// # 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<Self::State> {
/// # Ok(())
/// # }
///
/// async fn services(
/// registry: &mut ServiceRegistry<Self>,
/// context: &AppContext<Self::State>,
/// ) -> 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<App> for AppCli {
# #[allow(clippy::disallowed_types)]
# async fn run(
# &self,
# _app: &App,
# _cli: &AppCli,
# _context: &AppContext<()>,
# ) -> RoadsterResult<bool> {
# Ok(false)
# }
# }
# pub struct Migrator;
#
# #[async_trait::async_trait]
# impl MigratorTrait for Migrator {
# fn migrations() -> Vec<Box<dyn MigrationTrait>> {
# 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<Self::State> {
# Ok(())
# }
async fn services(
registry: &mut ServiceRegistry<Self>,
context: &AppContext<Self::State>,
) -> 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<A, F, Fut>
where
Expand Down

0 comments on commit e899d2d

Please sign in to comment.