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

refactor: service #225

Merged
merged 15 commits into from
Jul 5, 2022
Merged

refactor: service #225

merged 15 commits into from
Jul 5, 2022

Conversation

chesedo
Copy link
Contributor

@chesedo chesedo commented Jun 24, 2022

Make shuttle_service::Service easier to implement by users

Breaking changes

  • Axum service no longer use the SyncWrapper shim Maybe after deployer no longer has locks
  • declare_service! no longer exists. #[shuttle_service::main] should fill all needs
  • Any custom services need to change as follow:
    • Remove the build() method
    • bind() changed to the following
      async fn bind(mut self: Box<Self>, addr: SocketAddr) -> Result<(), shuttle_service::Error>;
      These changes are:
      • add async
      • remove the ref (&) on self
      • add : Box<Self> to self
      • change the Ok variant of the return result to ()
    • Remove the IntoService impl
    • (Optional) drop the async_trait dependency and use shuttle_service::async_trait instead

Example custom service

use shuttle_service::{Error, Service};

#[derive(Clone)]
pub struct MyService;

#[shuttle_service::async_trait]
impl Service for MyService {
    async fn bind(
        mut self: Box<Self>,
        _addr: std::net::SocketAddr,
    ) -> Result<(), shuttle_service::error::Error> {
        println!("service is binding");
        Ok(())
    }
}

#[shuttle_service::main]
async fn shuttle() -> Result<MyService, Error> {
    Ok(MyService {})
}

@nodard
Copy link
Contributor

nodard commented Jun 24, 2022

@chesedo chesedo requested a review from brokad June 27, 2022 14:57
Copy link
Collaborator

@brokad brokad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Nit which may help newcomers to this: StateBuilder<T> is basically ServiceBuilder<T: Service>. I wonder if we should document these internal types to make the crate more readable?

service/src/lib.rs Outdated Show resolved Hide resolved
@chesedo chesedo merged commit d61e628 into shuttle-hq:main Jul 5, 2022
@chesedo chesedo deleted the refactor/service branch July 5, 2022 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants