Probelm: Handler Error

| help: remove this mut

error[E0277]: the trait bound impl warp::Future<Output = Result<(), sqlx::Error>>: Handler<_> is not satisfied
--> src/main.rs:56:50
|
56 | .service(web::resource("/king").to(England()))
| -- ^^^^^^^^^ the trait Handler<_> is not implemented for impl warp::Future<Output = Result<(), sqlx::Error>>
| |
| required by a bound introduced by this call
|
note: required by a bound in Resource::<T>::to
--> /Users/mohanvenkatesh/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-4.3.1/src/resource.rs:240:12
|
240 | F: Handler,
| ^^^^^^^^^^^^^ required by this bound in Resource::<T>::to

Please check this and help me

https://github.dev/MohanSharmav/blog_rust_2

looking at the document, Handler is implemented for async functions, not for Futures. in your code, England is an async function, while calling it England() results a Future. try remove the parenthesis.

1 Like

I removed the parenthesis and tried but still this error appears

= note: required for Result<(), sqlx::Error> to implement Responder
note: required by a bound in Resource::<T>::to
--> /Users/mohanvenkatesh/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-4.3.1/src/resource.rs:242:20
|
242 | F::Output: Responder + 'static,
| ^^^^^^^^^ required by this bound in Resource::<T>::to

error[E0277]: the trait bound sqlx::Error: ResponseError is not satisfied
--> src/main.rs:56:50
|
56 | .service(web::resource("/king").to(England))
| -- ^^^^^^^ the trait ResponseError is not implemented for sqlx::Error
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait ResponseError:
BlockingError
Box<(dyn StdError + 'static)>
HttpError
Infallible
InvalidHeaderValue
JsonPayloadError
PathError
PayloadError
and 18 others
= note: required for actix_web::Error to implement std::convert::From<sqlx::Error>
= note: required for sqlx::Error to implement Into<actix_web::Error>
= note: required for Result<(), sqlx::Error> to implement Responder
note: required by a bound in Resource::<T>::to
--> /Users/mohanvenkatesh/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-web-4.3.1/src/resource.rs:242:20
|
242 | F::Output: Responder + 'static,
| ^^^^^^^^^ required by this bound in Resource::<T>::to

For more information about

the to method has the following bounds:

where
    F: Handler<Args>,
    Args: FromRequest + 'static,
    F::Output: Responder + 'static,

the compiler pointed out the the last one is not met. the document says Responder is implemented for Result<T, E> if T: Reponder, E: ResponseError, so apparently your function returns Result<(), sqlx::Error>, where the sqlx::Error type doesn't have a ReponseError implementation.

you need to convert the error type into something that implements the ResponseError trait, you can either create your own error type or pick one of the error types provided by actix such as InernalError

please learn to read the compiler output and the documentations you are using. they are there for a reason.