-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
AppEntry inaccessible due to app_service being a private module #2039
Comments
It's possible and you don't need the use actix_service::ServiceFactory;
use actix_web::dev::{Body, ServiceRequest, ServiceResponse};
use actix_web::middleware::{Compat, Logger};
use actix_web::{get, App, Error, HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| app())
.bind("127.0.0.1:8080")?
.run()
.await
}
fn app() -> App<
impl ServiceFactory<
ServiceRequest,
Config = (),
Response = ServiceResponse,
Error = Error,
InitError = (),
>,
Body,
> {
App::new()
.wrap(Compat::new(Logger::default()))
.service(index)
}
#[get("/hi")]
async fn index() -> &'static str {
"Hello World!"
} In general do not return an App instance unless you have a very good understanding of how to describe the complicated types App returns. It wants an opaque type that impl |
Your code does not compile with the latest stable release |
App::configure is the recommended solution. |
Sorry the code is for actix-web v4. For actix-web v3 there is no Compat middleware to help you figure out the body type but you can try this if you don't wrap any middleware. use actix_service::ServiceFactory;
use actix_web::dev::{Body, ServiceRequest, ServiceResponse};
use actix_web::{get, App, Error, HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| app())
.bind("127.0.0.1:8080")?
.run()
.await
}
fn app() -> App<
impl ServiceFactory<
Request = ServiceRequest,
Config = (),
Response = ServiceResponse,
Error = Error,
InitError = (),
>,
Body,
> {
App::new().service(index)
}
#[get("/hi")]
async fn index() -> &'static str {
"Hello World!"
} This is why I said if you don't know how the types return needed to be you would have hard time to figure it out. |
Hi there,
I was hoping to make a function that returns an
App
, but because it takes two generic types, one of which defaults toAppEntry
, that was impossible. It would be nice if theapp_service
module was public so we can do this.The text was updated successfully, but these errors were encountered: