-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: draft of extracting service integrations
- Loading branch information
Showing
6 changed files
with
158 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 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 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 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-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] | ||
async-trait = "0.1.56" | ||
axum = { version = "0.6.0" } | ||
shuttle-runtime = { path = "../../runtime", version = "0.1.0" } |
This file contains 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,39 @@ | ||
//! Shuttle service integration for the Axum web framework. | ||
//! ## Example | ||
//! ```rust,no_run | ||
//! use shuttle_axum::AxumService; | ||
//! | ||
//! async fn hello_world() -> &'static str { | ||
//! "Hello, world!" | ||
//! } | ||
//! | ||
//! #[shuttle_axum::main] | ||
//! async fn axum() -> shuttle_service::ShuttleAxum { | ||
//! let router = Router::new().route("/hello", get(hello_world)); | ||
//! | ||
//! Ok(AxumService(router)) | ||
//! } | ||
//! ``` | ||
/// 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: std::net::SocketAddr) -> Result<(), shuttle_runtime::Error> { | ||
axum::Server::bind(&addr) | ||
.serve(self.0.into_make_service()) | ||
.await | ||
.map_err(shuttle_runtime::CustomError::new)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
/// The return type that should be returned from the `shuttle_runtime::main` function. | ||
pub type ShuttleAxum = Result<AxumService, shuttle_runtime::Error>; | ||
|
||
pub use shuttle_runtime; | ||
pub use shuttle_runtime::*; |
This file contains 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