-
Notifications
You must be signed in to change notification settings - Fork 273
feat: extract service integrations into separate crates #702
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
Merged
oddgrd
merged 29 commits into
shuttle-hq:shuttle-next
from
oddgrd:feature/eng-490-extract-the-service-integrations-into
Mar 13, 2023
Merged
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
9508d42
feat: draft of extracting service integrations
oddgrd 5bde6a3
refactor: revert codegen changes
oddgrd 275c632
refactor: depend on shuttle_runtime & service integration
oddgrd 2788e9a
feat: remove rocket bin, comment out version check
oddgrd ff57736
feat: impl from for integration wrapper
oddgrd 966eb3c
feat: cleanup shuttle-axum docs, remove version check
oddgrd 994b9cc
feat: actix-web service integration
oddgrd 19ef966
feat: extract poem service integration
oddgrd c6d2033
feat: extract poise service integration
oddgrd 017c9c2
feat: extract rocket service integration
oddgrd 3257234
feat: extract salvo service integration
oddgrd d042562
feat: extract the serenity service integration
oddgrd 68955b9
feat: extract the thruster service integration
oddgrd 916f989
feat: extract warp service integration
oddgrd 94531de
feat: extract the tower service integration
oddgrd 3b66433
feat: delete persist from service
oddgrd a9128f8
feat: extract tide service integration
oddgrd f0aefe2
feat: update cargo.lock
oddgrd 5659b23
Merge branch 'shuttle-next' into feature/eng-490-extract-the-service-…
oddgrd 131cf6b
feat: make service integration inner pub
oddgrd 41e0127
Merge remote-tracking branch 'upstream/shuttle-next' into feature/eng…
oddgrd 22a6a23
fix: merge fixes
oddgrd 830c2d1
refactor: rename integrations, remove comment
oddgrd 6b03a74
ci: run check-standalone on services
oddgrd fbd88ff
Merge branch 'shuttle-next' into feature/eng-490-extract-the-service-…
oddgrd 6ae1d49
feat: update test resources
oddgrd eecda1e
ci: refactor workspace-clippy job
oddgrd 5ab7994
fix: add tokio dev dep to services
oddgrd 4dfc724
fix: remaining services tests
oddgrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Service Integrations | ||
The list of supported frameworks for shuttle is always growing. If you feel we are missing a framework you would like, then feel to create a feature request for your desired framework. | ||
|
||
## Writing your own service integration | ||
Creating your own service integration is quite simple. You only need to implement the [`Service`](https://docs.rs/shuttle-service/latest/shuttle_service/trait.Service.html) trait for your framework. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "shuttle-actix-web" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
actix-web = { version = "4.3.1" } | ||
shuttle-runtime = { path = "../../runtime", version = "0.1.0" } | ||
num_cpus = "1.15.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Shuttle service integration for the Actix Web framework. | ||
//! ## Example | ||
//! ```rust,no_run | ||
//! use actix_web::{get, web::ServiceConfig}; | ||
//! use shuttle_actix_web::ShuttleActixWeb; | ||
//! | ||
//! #[get("/hello")] | ||
//! 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()) | ||
//! } | ||
//! ``` | ||
use std::net::SocketAddr; | ||
|
||
/// A wrapper type for a closure that returns an [actix_web::web::ServiceConfig] so we can implement | ||
/// [shuttle_runtime::Service] for it. | ||
#[derive(Clone)] | ||
pub struct ActixWebService<F>(pub F); | ||
|
||
#[shuttle_runtime::async_trait] | ||
impl<F> shuttle_runtime::Service for ActixWebService<F> | ||
where | ||
F: FnOnce(&mut actix_web::web::ServiceConfig) + Send + Clone + 'static, | ||
{ | ||
async fn bind(mut self, addr: SocketAddr) -> Result<(), shuttle_runtime::Error> { | ||
// Start a worker for each cpu, but no more than 4. | ||
let worker_count = num_cpus::get().min(4); | ||
|
||
let server = | ||
actix_web::HttpServer::new(move || actix_web::App::new().configure(self.0.clone())) | ||
.workers(worker_count) | ||
.bind(addr)? | ||
.run(); | ||
|
||
server.await.map_err(shuttle_runtime::CustomError::new)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl<F> From<F> for ActixWebService<F> | ||
where | ||
F: FnOnce(&mut actix_web::web::ServiceConfig) + Send + Clone + 'static, | ||
{ | ||
fn from(service_config: F) -> Self { | ||
Self(service_config) | ||
} | ||
} | ||
|
||
/// The return type that should be returned from the [shuttle_runtime::main] function. | ||
pub type ShuttleActixWeb<F> = Result<ActixWebService<F>, shuttle_runtime::Error>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "shuttle-axum" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
axum = { version = "0.6.10" } | ||
shuttle-runtime = { path = "../../runtime", version = "0.1.0" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! 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("/hello", get(hello_world)); | ||
//! | ||
//! Ok(router.into()) | ||
//! } | ||
//! ``` | ||
use shuttle_runtime::{CustomError, Error}; | ||
use std::net::SocketAddr; | ||
|
||
/// A wrapper type for [axum::Router] so we can implement [shuttle_runtime::Service] for it. | ||
pub struct AxumService(pub axum::Router); | ||
|
||
#[shuttle_runtime::async_trait] | ||
impl shuttle_runtime::Service for AxumService { | ||
/// Takes the router that is returned by the user in their [shuttle_runtime::main] function | ||
/// and binds to an address passed in by shuttle. | ||
async fn bind(mut self, addr: SocketAddr) -> Result<(), Error> { | ||
axum::Server::bind(&addr) | ||
.serve(self.0.into_make_service()) | ||
.await | ||
.map_err(CustomError::new)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl From<axum::Router> for AxumService { | ||
fn from(router: axum::Router) -> Self { | ||
Self(router) | ||
} | ||
} | ||
/// The return type that should be returned from the [shuttle_runtime::main] function. | ||
pub type ShuttleAxum = Result<AxumService, Error>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "shuttle-poem" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
poem = { version = "1.3.55" } | ||
shuttle-runtime = { path = "../../runtime", version = "0.1.0" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! 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("/hello", get(hello_world)); | ||
//! | ||
//! Ok(app.into()) | ||
//! } | ||
//! | ||
//! ``` | ||
|
||
/// A wrapper type for [poem::Endpoint] so we can implement [shuttle_runtime::Service] for it. | ||
pub struct PoemService<T>(pub T); | ||
|
||
#[shuttle_runtime::async_trait] | ||
impl<T> shuttle_runtime::Service for PoemService<T> | ||
where | ||
T: poem::Endpoint + Send + 'static, | ||
{ | ||
async fn bind(mut self, addr: std::net::SocketAddr) -> Result<(), shuttle_runtime::Error> { | ||
poem::Server::new(poem::listener::TcpListener::bind(addr)) | ||
.run(self.0) | ||
.await | ||
.map_err(shuttle_runtime::CustomError::new)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl<T> From<T> for PoemService<T> | ||
where | ||
T: poem::Endpoint + Send + 'static, | ||
{ | ||
fn from(router: T) -> Self { | ||
Self(router) | ||
} | ||
} | ||
|
||
/// The return type that should be returned from the [shuttle_runtime::main] function. | ||
pub type ShuttlePoem<T> = Result<PoemService<T>, shuttle_runtime::Error>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "shuttle-poise" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
poise = { version = "0.5.2" } | ||
shuttle-runtime = { path = "../../runtime", version = "0.1.0" } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.