Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: service docs readme #1425

Merged
merged 5 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions services/shuttle-actix-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Shuttle service integration for the Actix Web framework.

### Example

```rust,no_run
use actix_web::{get, web::ServiceConfig};
use shuttle_actix_web::ShuttleActixWeb;

#[get("/")]
async fn hello_world() -> &'static str {
"Hello World!"
}

#[shuttle_runtime::main]
async fn actix_web() -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
let config = move |cfg: &mut ServiceConfig| {
cfg.service(hello_world);
};

Ok(config.into())
}

```
38 changes: 2 additions & 36 deletions services/shuttle-actix-web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
//! Shuttle service integration for the Actix Web framework.
//!
//! ## Example
//!
//! ```rust,no_run
//! use actix_web::{get, web::ServiceConfig};
//! use shuttle_actix_web::ShuttleActixWeb;
//!
//! #[get("/")]
//! async fn hello_world() -> &'static str {
//! "Hello World!"
//! }
//!
//! #[shuttle_runtime::main]
//! async fn actix_web() -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
//! let config = move |cfg: &mut ServiceConfig| {
//! cfg.service(hello_world);
//! };
//!
//! Ok(config.into())
//! }
//! ```

#![doc = include_str!("../README.md")]
use std::net::SocketAddr;

/// A wrapper type for a closure that returns an [actix_web::web::ServiceConfig] so we can implement
Expand Down Expand Up @@ -58,17 +36,5 @@ where
}
}

/// Return type from the `[shuttle_runtime::main]` macro for an Actix-based service.
///
/// # Example
/// ```rust,no_run
/// # use shuttle_actix_web::ShuttleActixWeb;
/// # use actix_web::web::ServiceConfig;
///
/// #[shuttle_runtime::main]
/// async fn example_service() -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
/// let config = move |_cfg: &mut ServiceConfig| {};
/// Ok(config.into())
/// }
/// ```
#[doc = include_str!("../README.md")]
pub type ShuttleActixWeb<F> = Result<ActixWebService<F>, shuttle_runtime::Error>;
18 changes: 18 additions & 0 deletions services/shuttle-axum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Shuttle service integration for the Axum web framework.

### Example

```rust,no_run
use axum::{routing::get, Router};

async fn hello_world() -> &'static str {
"Hello, world!"
}

#[shuttle_runtime::main]
async fn axum() -> shuttle_axum::ShuttleAxum {
let router = Router::new().route("/", get(hello_world));

Ok(router.into())
}
```
38 changes: 2 additions & 36 deletions services/shuttle-axum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
//! Shuttle service integration for the Axum web framework.
//!
//! ## Example
//!
//! ```rust,no_run
//! use axum::{routing::get, Router};
//!
//! async fn hello_world() -> &'static str {
//! "Hello, world!"
//! }
//!
//! #[shuttle_runtime::main]
//! async fn axum() -> shuttle_axum::ShuttleAxum {
//! let router = Router::new().route("/", get(hello_world));
//!
//! Ok(router.into())
//! }
//! ```
#![doc = include_str!("../README.md")]
use shuttle_runtime::{CustomError, Error};
use std::net::SocketAddr;

Expand All @@ -42,22 +25,5 @@ impl From<axum::Router> for AxumService {
}
}

/// Return type from the `[shuttle_runtime::main]` macro for a Axum-based service.
///
/// ## Example
///
/// ```rust,no_run
/// use axum::{routing::get, Router};
///
/// async fn hello_world() -> &'static str {
/// "Hello, world!"
/// }
///
/// #[shuttle_runtime::main]
/// async fn axum() -> shuttle_axum::ShuttleAxum {
/// let router = Router::new().route("/", get(hello_world));
///
/// Ok(router.into())
/// }
/// ```
#[doc = include_str!("../README.md")]
pub type ShuttleAxum = Result<AxumService, Error>;
20 changes: 20 additions & 0 deletions services/shuttle-poem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Shuttle service integration for the Poem web framework.

### Example

```rust,no_run
use poem::{get, handler, Route};
use shuttle_poem::ShuttlePoem;

#[handler]
fn hello_world() -> &'static str {
"Hello, world!"
}

#[shuttle_runtime::main]
async fn poem() -> ShuttlePoem<impl poem::Endpoint> {
let app = Route::new().at("/", get(hello_world));

Ok(app.into())
}
```
41 changes: 2 additions & 39 deletions services/shuttle-poem/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
//! Shuttle service integration for the Poem web framework.
//! ## Example
//! ```rust,no_run
//! use poem::{get, handler, Route};
//! use shuttle_poem::ShuttlePoem;
//!
//! #[handler]
//! fn hello_world() -> &'static str {
//! "Hello, world!"
//! }
//!
//! #[shuttle_runtime::main]
//! async fn poem() -> ShuttlePoem<impl poem::Endpoint> {
//! let app = Route::new().at("/", get(hello_world));
//!
//! Ok(app.into())
//! }
//!
//! ```

#![doc = include_str!("../README.md")]
/// A wrapper type for [poem::Endpoint] so we can implement [shuttle_runtime::Service] for it.
pub struct PoemService<T>(pub T);

Expand Down Expand Up @@ -45,23 +26,5 @@ where
}
}

/// Return type from the `[shuttle_runtime::main]` macro for a Poem-based service.
///
/// # Example
///
/// ```rust,no_run
/// use poem::{get, handler, Route};
/// use shuttle_poem::ShuttlePoem;
/// #[handler]
/// fn hello_world() -> &'static str {
/// "Hello, world!"
/// }
///
/// #[shuttle_runtime::main]
/// async fn poem() -> ShuttlePoem<impl poem::Endpoint> {
/// let app = Route::new().at("/", get(hello_world));
///
/// Ok(app.into())
/// }
/// ```
#[doc = include_str!("../README.md")]
pub type ShuttlePoem<T> = Result<PoemService<T>, shuttle_runtime::Error>;
47 changes: 47 additions & 0 deletions services/shuttle-poise/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## Shuttle service integration for the Poise discord bot framework.

### Example

```rust,no_run
use poise::serenity_prelude as serenity;
use shuttle_secrets::SecretStore;
use shuttle_poise::ShuttlePoise;

struct Data {} // User data, which is stored and accessible in all command invocations
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;

/// Responds with "world!"
#[poise::command(slash_command)]
async fn hello(ctx: Context<'_>) -> Result<(), Error> {
ctx.say("world!").await?;
Ok(())
}

#[shuttle_runtime::main]
async fn poise(#[shuttle_secrets::Secrets] secret_store: SecretStore) -> ShuttlePoise<Data, Error> {
// Get the discord token set in `Secrets.toml`
let discord_token = secret_store
.get("DISCORD_TOKEN")
.expect("'DISCORD_TOKEN' was not found");

let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![hello()],
..Default::default()
})
.token(discord_token)
.intents(serenity::GatewayIntents::non_privileged())
.setup(|ctx, _ready, framework| {
Box::pin(async move {
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
Ok(Data {})
})
})
.build()
.await
.map_err(shuttle_runtime::CustomError::new)?;

Ok(framework.into())
}
```
96 changes: 2 additions & 94 deletions services/shuttle-poise/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,4 @@
//! Shuttle service integration for the Poise discord bot framework.
//!
//! ## Example
//!
//! ```rust,no_run
//! use poise::serenity_prelude as serenity;
//! use shuttle_secrets::SecretStore;
//! use shuttle_poise::ShuttlePoise;
//!
//! struct Data {} // User data, which is stored and accessible in all command invocations
//! type Error = Box<dyn std::error::Error + Send + Sync>;
//! type Context<'a> = poise::Context<'a, Data, Error>;
//!
//! /// Responds with "world!"
//! #[poise::command(slash_command)]
//! async fn hello(ctx: Context<'_>) -> Result<(), Error> {
//! ctx.say("world!").await?;
//! Ok(())
//! }
//!
//! #[shuttle_runtime::main]
//! async fn poise(#[shuttle_secrets::Secrets] secret_store: SecretStore) -> ShuttlePoise<Data, Error> {
//! // Get the discord token set in `Secrets.toml`
//! let discord_token = secret_store
//! .get("DISCORD_TOKEN")
//! .expect("'DISCORD_TOKEN' was not found");
//!
//! let framework = poise::Framework::builder()
//! .options(poise::FrameworkOptions {
//! commands: vec![hello()],
//! ..Default::default()
//! })
//! .token(discord_token)
//! .intents(serenity::GatewayIntents::non_privileged())
//! .setup(|ctx, _ready, framework| {
//! Box::pin(async move {
//! poise::builtins::register_globally(ctx, &framework.options().commands).await?;
//! Ok(Data {})
//! })
//! })
//! .build()
//! .await
//! .map_err(shuttle_runtime::CustomError::new)?;
//!
//! Ok(framework.into())
//! }
//! ```
#![doc = include_str!("../README.md")]
use std::net::SocketAddr;
use std::sync::Arc;

Expand Down Expand Up @@ -73,51 +27,5 @@ impl<T, E> From<Arc<poise::Framework<T, E>>> for PoiseService<T, E> {
}
}

/// Return type from the `[shuttle_runtime::main]` macro for a Poise-based service.
///
/// ## Example
///
/// ```rust,no_run
/// use poise::serenity_prelude as serenity;
/// use shuttle_secrets::SecretStore;
/// use shuttle_poise::ShuttlePoise;
///
/// struct Data {} // User data, which is stored and accessible in all command invocations
/// type Error = Box<dyn std::error::Error + Send + Sync>;
/// type Context<'a> = poise::Context<'a, Data, Error>;
///
///
/// #[poise::command(slash_command)]
/// async fn hello(ctx: Context<'_>) -> Result<(), Error> {
/// ctx.say("world!").await?;
/// Ok(())
/// }
///
/// #[shuttle_runtime::main]
/// async fn poise(#[shuttle_secrets::Secrets] secret_store: SecretStore) -> ShuttlePoise<Data, Error> {
///
/// let discord_token = secret_store
/// .get("DISCORD_TOKEN")
/// .expect("'DISCORD_TOKEN' was not found");
///
/// let framework = poise::Framework::builder()
/// .options(poise::FrameworkOptions {
/// commands: vec![hello()],
/// ..Default::default()
/// })
/// .token(discord_token)
/// .intents(serenity::GatewayIntents::non_privileged())
/// .setup(|ctx, _ready, framework| {
/// Box::pin(async move {
/// poise::builtins::register_globally(ctx, &framework.options().commands).await?;
/// Ok(Data {})
/// })
/// })
/// .build()
/// .await
/// .map_err(shuttle_runtime::CustomError::new)?;
///
/// Ok(framework.into())
/// }
/// ```
#[doc = include_str!("../README.md")]
pub type ShuttlePoise<T, E> = Result<PoiseService<T, E>, shuttle_runtime::Error>;
22 changes: 22 additions & 0 deletions services/shuttle-rocket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Shuttle service integration for the Rocket web framework.

### Example

```rust,no_run
#[macro_use]
extern crate rocket;

# fn main() {
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}

#[shuttle_runtime::main]
async fn rocket() -> shuttle_rocket::ShuttleRocket {
let rocket = rocket::build().mount("/", routes![index]);

Ok(rocket.into())
}
# }
```
Loading