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

Documentation updates for return types #893

Merged
merged 52 commits into from Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e5fa731
docs(axum): add return type docs for ShuttleAxum
AliSajid May 9, 2023
2d7b629
docs(poem): add return type docs for poem
AliSajid May 9, 2023
db4e3f8
docs(poise): return type docs for poise based service
AliSajid May 9, 2023
a66f8b5
docs(rocket): add return type docs for Rocket
AliSajid May 9, 2023
726c3b3
docs(salvo): add return types for salvo
AliSajid May 9, 2023
b56c1af
style: add closing code fence for docs
AliSajid May 9, 2023
eb76262
docs(thruster): add return type docs for thruster
AliSajid May 9, 2023
41edff8
docs(warp): return type docs for the warp service
AliSajid May 9, 2023
fe28e07
docs(tide): update return type for tide
AliSajid May 9, 2023
9e2057c
docs(service-errors): add documentation for service error types
AliSajid May 9, 2023
642a489
style: fix format error on services
AliSajid May 9, 2023
7c3ea0f
style(errors): fix formatting issues
AliSajid May 12, 2023
a9cdf6c
Merge branch 'main' into intellisense
iulianbarbu May 17, 2023
5e0ca60
Merge branch 'shuttle-hq:main' into intellisense
AliSajid May 22, 2023
11e7a6f
chore: complete merge of the upstream changes
AliSajid May 27, 2023
99eba64
docs(poem): add return type docs for poem
AliSajid May 9, 2023
ae34bbe
docs(poise): return type docs for poise based service
AliSajid May 9, 2023
257d5b8
docs(rocket): add return type docs for Rocket
AliSajid May 9, 2023
24916e1
docs(salvo): add return types for salvo
AliSajid May 9, 2023
254f5bc
style: add closing code fence for docs
AliSajid May 9, 2023
4343cef
docs(thruster): add return type docs for thruster
AliSajid May 9, 2023
0e4a1b0
docs(warp): return type docs for the warp service
AliSajid May 9, 2023
539a501
docs(tide): update return type for tide
AliSajid May 9, 2023
bfd1266
docs(service-errors): add documentation for service error types
AliSajid May 9, 2023
8481eb7
style: fix format error on services
AliSajid May 9, 2023
8311a28
style(errors): fix formatting issues
AliSajid May 12, 2023
72b1759
chore: complete merge of the upstream changes
AliSajid May 27, 2023
88b4311
build: update cargo dependencies on cargo.lock
AliSajid May 27, 2023
d951cf9
docs(axum): add type annotation for ShuttleAxum
AliSajid May 27, 2023
27c2792
docs(poem): complete the type docs for passing tests
AliSajid May 27, 2023
d0af69b
style(poem): reformat code for poem lib
AliSajid May 27, 2023
73171bc
docs(rocket): update type docs for ShuttleRocket
AliSajid May 27, 2023
066fdc1
docs(salvo): update docs for salvo to pass tests
AliSajid May 27, 2023
e69f7a9
docs(thruster): update the docs for test passage
AliSajid May 27, 2023
53a4641
docs(tide): update type docs for tide
AliSajid May 27, 2023
6314ccc
docs(axum): update docs to align with examples
AliSajid May 27, 2023
d4ea191
docs(poem): update docs to align with official docs
AliSajid May 27, 2023
8387730
docs(rocket): update the example to align with official docs
AliSajid May 28, 2023
78caf4a
docs(salvo): update docs to align with official examples
AliSajid May 28, 2023
980ca54
docs(thruster): update docs to align with official examples
AliSajid May 28, 2023
43f7c8d
docs(tide): update docs to align with official example
AliSajid May 28, 2023
7a2b4eb
docs(warp): update docs to align with the official examples
AliSajid May 28, 2023
74a5ac4
docs(poise): update docs with the official examples
AliSajid May 28, 2023
67b8212
style: refomat doc-tests for compliance
AliSajid May 28, 2023
270b4f2
docs: trim service error comment
oddgrd Jun 1, 2023
d3db080
Merge remote-tracking branch 'upstream/main' into intellisense
jonaro00 Oct 28, 2023
e1ed550
docs: use root endpoint
jonaro00 Oct 28, 2023
7540279
docs: remove more /hello
jonaro00 Oct 28, 2023
7c36210
nits
jonaro00 Oct 28, 2023
9a34060
Merge remote-tracking branch 'upstream/main' into intellisense
jonaro00 Oct 28, 2023
5db97d6
Merge remote-tracking branch 'upstream/main' into intellisense
jonaro00 Oct 28, 2023
5105c38
docs: fix poise doc
jonaro00 Oct 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions service/src/error.rs
Expand Up @@ -2,16 +2,22 @@

use thiserror::Error;

/// An error that can occur in the process of building and deploying a service.
#[derive(Debug, Error)]
pub enum Error {
/// An Input/Output error.
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
/// An Error related to the database.
#[error("Database error: {0}")]
Database(String),
/// An error related to the build process.
#[error("Panic occurred in shuttle_service::main`: {0}")]
BuildPanic(String),
/// An error related to the bind process.
#[error("Panic occurred in `Service::bind`: {0}")]
BindPanic(String),
/// An error related to parsing the Secrets.toml file.
#[error("Failed to interpolate string. Is your Secrets.toml correct?")]
StringInterpolation(#[from] strfmt::FmtError),
#[error(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion services/shuttle-actix-web/src/lib.rs
Expand Up @@ -6,7 +6,7 @@
//! use actix_web::{get, web::ServiceConfig};
//! use shuttle_actix_web::ShuttleActixWeb;
//!
//! #[get("/hello")]
//! #[get("/")]
//! async fn hello_world() -> &'static str {
//! "Hello World!"
//! }
Expand Down
24 changes: 22 additions & 2 deletions services/shuttle-axum/src/lib.rs
@@ -1,5 +1,7 @@
//! Shuttle service integration for the Axum web framework.
//!
//! ## Example
//!
//! ```rust,no_run
//! use axum::{routing::get, Router};
//!
Expand All @@ -9,7 +11,7 @@
//!
//! #[shuttle_runtime::main]
//! async fn axum() -> shuttle_axum::ShuttleAxum {
//! let router = Router::new().route("/hello", get(hello_world));
//! let router = Router::new().route("/", get(hello_world));
//!
//! Ok(router.into())
//! }
Expand Down Expand Up @@ -39,5 +41,23 @@ impl From<axum::Router> for AxumService {
Self(router)
}
}
/// The return type that should be returned from the [shuttle_runtime::main] function.

/// 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())
/// }
/// ```
pub type ShuttleAxum = Result<AxumService, Error>;
22 changes: 20 additions & 2 deletions services/shuttle-poem/src/lib.rs
Expand Up @@ -11,7 +11,7 @@
//!
//! #[shuttle_runtime::main]
//! async fn poem() -> ShuttlePoem<impl poem::Endpoint> {
//! let app = Route::new().at("/hello", get(hello_world));
//! let app = Route::new().at("/", get(hello_world));
//!
//! Ok(app.into())
//! }
Expand Down Expand Up @@ -45,5 +45,23 @@ where
}
}

/// The return type that should be returned from the [shuttle_runtime::main] function.
/// 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())
/// }
/// ```
pub type ShuttlePoem<T> = Result<PoemService<T>, shuttle_runtime::Error>;
50 changes: 49 additions & 1 deletion services/shuttle-poise/src/lib.rs
@@ -1,5 +1,7 @@
//! Shuttle service integration for the Poise discord bot framework.
//!
//! ## Example
//!
//! ```rust,no_run
//! use poise::serenity_prelude as serenity;
//! use shuttle_secrets::SecretStore;
Expand Down Expand Up @@ -71,5 +73,51 @@ impl<T, E> From<Arc<poise::Framework<T, E>>> for PoiseService<T, E> {
}
}

/// The return type that should be returned from the [shuttle_runtime::main] function.
/// 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())
/// }
/// ```
pub type ShuttlePoise<T, E> = Result<PoiseService<T, E>, shuttle_runtime::Error>;
23 changes: 21 additions & 2 deletions services/shuttle-rocket/src/lib.rs
Expand Up @@ -12,7 +12,7 @@
//!
//! #[shuttle_runtime::main]
//! async fn rocket() -> shuttle_rocket::ShuttleRocket {
//! let rocket = rocket::build().mount("/hello", routes![index]);
//! let rocket = rocket::build().mount("/", routes![index]);
//!
//! Ok(rocket.into())
//! }
Expand Down Expand Up @@ -59,5 +59,24 @@ impl From<rocket::Rocket<rocket::Build>> for RocketService {
}
}

/// The return type that should be returned from the [shuttle_runtime::main] function.
/// Return type from the `[shuttle_runtime::main]` macro for a Rocket-based service.
///
/// # Example
///
/// ```rust,no_run
/// use rocket::{routes, get};
/// use shuttle_rocket::ShuttleRocket;
///
/// #[get("/")]
/// fn index() -> &'static str {
/// "Hello, world!"
/// }
///
/// #[shuttle_runtime::main]
/// async fn rocket() -> ShuttleRocket {
/// let rocket = rocket::build().mount("/", routes![index]);
///
/// Ok(rocket.into())
/// }
/// ```
pub type ShuttleRocket = Result<RocketService, shuttle_runtime::Error>;
22 changes: 21 additions & 1 deletion services/shuttle-salvo/src/lib.rs
Expand Up @@ -41,5 +41,25 @@ impl From<salvo::Router> for SalvoService {
Self(router)
}
}
/// The return type that should be returned from the [shuttle_runtime::main] function.

/// Return type from the `[shuttle_runtime::main]` macro for a Salvo-based service.
///
/// # Example
///
/// ```rust,no_run
/// use salvo::prelude::*;
/// use shuttle_salvo::ShuttleSalvo;
///
/// #[handler]
/// async fn hello_world(res: &mut Response) {
/// res.render(Text::Plain("Hello, world!"));
/// }
///
/// #[shuttle_runtime::main]
/// async fn salvo() -> ShuttleSalvo {
/// let router = Router::with_path("hello").get(hello_world);
///
/// Ok(router.into())
/// }
/// ```
pub type ShuttleSalvo = Result<SalvoService, Error>;
32 changes: 29 additions & 3 deletions services/shuttle-thruster/src/lib.rs
@@ -1,5 +1,7 @@
//! Shuttle service integration for the Thruster web framework.
//!
//! ## Example
//!
//! ```rust,no_run
//! use thruster::{
//! context::basic_hyper_context::{generate_context, BasicHyperContext as Ctx, HyperRequest},
Expand All @@ -15,9 +17,9 @@
//! #[shuttle_runtime::main]
//! async fn thruster() -> shuttle_thruster::ShuttleThruster<HyperServer<Ctx, ()>> {
//! let server = HyperServer::new(
//! App::<HyperRequest, Ctx, ()>::create(generate_context, ()).get("/hello", m![hello]),
//! App::<HyperRequest, Ctx, ()>::create(generate_context, ()).get("/", m![hello]),
//! );
//!
//!
//! Ok(server.into())
//! }
//! ```
Expand Down Expand Up @@ -49,5 +51,29 @@ where
Self(router)
}
}
/// The return type that should be returned from the [shuttle_runtime::main] function.

/// The return type of the [shuttle_runtime::main] function for the Thruster service.
///
/// ## Example
///
/// ```rust,no_run
/// use shuttle_thruster::ShuttleThruster;
/// use thruster::{
/// context::basic_hyper_context::{generate_context, BasicHyperContext as Ctx, HyperRequest},
/// m, middleware_fn, App, HyperServer, MiddlewareNext, MiddlewareResult, ThrusterServer,
/// };
///
/// #[middleware_fn]
/// async fn hello(mut context: Ctx, _next: MiddlewareNext<Ctx>) -> MiddlewareResult<Ctx> {
/// context.body("Hello, World!");
/// Ok(context)
/// }
///
/// #[shuttle_runtime::main]
/// async fn thruster() -> ShuttleThruster<HyperServer<Ctx, ()>> {
/// Ok(HyperServer::new(
/// App::<HyperRequest, Ctx, ()>::create(generate_context, ()).get("/", m![hello]),
/// ).into())
/// }
/// ```
pub type ShuttleThruster<T> = Result<ThrusterService<T>, Error>;
2 changes: 1 addition & 1 deletion services/shuttle-tide/src/lib.rs
Expand Up @@ -8,7 +8,7 @@
//! let mut app = tide::new();
//! app.with(tide::log::LogMiddleware::new());
//!
//! app.at("/hello").get(|_| async { Ok("Hello, world!") });
//! app.at("/").get(|_| async { Ok("Hello, world!") });
//!
//! Ok(app.into())
//! }
Expand Down
18 changes: 17 additions & 1 deletion services/shuttle-warp/src/lib.rs
@@ -1,5 +1,7 @@
//! Shuttle service integration for the Warp web framework.
//!
//! ## Example
//!
//! ```rust,no_run
//! use warp::Filter;
//! use warp::Reply;
Expand Down Expand Up @@ -49,5 +51,19 @@ impl<T> Deref for WarpService<T> {
}
}

/// The return type that should be returned from the [shuttle_runtime::main] function.
/// The return type of the [shuttle_runtime::main] function for the Warp service.
///
/// ## Example
///
/// ```rust,no_run
/// use shuttle_warp::ShuttleWarp;
/// use warp::Filter;
/// use warp::Reply;
///
/// #[shuttle_runtime::main]
/// async fn warp() -> ShuttleWarp<(impl Reply,)> {
/// let route = warp::any().map(|| "Hello, World");
/// Ok(route.boxed().into())
/// }
/// ```
pub type ShuttleWarp<T> = Result<WarpService<warp::filters::BoxedFilter<T>>, Error>;