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

the trait ResponseError is not implemented for jammdb::Error #5

Closed
ArunGust opened this issue Feb 7, 2021 · 6 comments
Closed

the trait ResponseError is not implemented for jammdb::Error #5

ArunGust opened this issue Feb 7, 2021 · 6 comments

Comments

@ArunGust
Copy link

ArunGust commented Feb 7, 2021

Hi,

I got the below error for integration with actix web app. Anyway, idea how to resolve this?

let mut tx = _jdb.tx(true)?;
| ^ the trait ResponseError is not implemented for jammdb::Error

@pjtatlow
Copy link
Owner

pjtatlow commented Feb 7, 2021

Hi @ArunGust

Your problem is that you are using the ? operator, which returns the error from the tx method, which if of type jammdb::Error. But I'm assuming the function you're using this in returns an error type of actix_web::ResponseError, which isn't satisfied by a jammdb::Error.

You should look into using something like map_err to convert the jammdb::Error into something that satisfies the ResponseError trait, or create another type that implements From<jammdb::Error> as well as actix_web::ResponseError and return that instead!

Hopefully that helps!

@pjtatlow pjtatlow closed this as completed Feb 7, 2021
@ArunGust
Copy link
Author

ArunGust commented Feb 9, 2021

Thank you @pjtatlow

I tried to clone and pass-through Arc, but it shows [E0596] cannot borrow data in an Arc as mutable. Any idea ?

let jdb = jammdb::DB::open("../jammdb").unwrap();
HttpServer::new(move || {
    App::new()
        .data(jdb.clone())

async fn fn_inituserdb(req: HttpRequest, _jdb: Datajammdb::DB) ->Result<String, Error> {
33 | let _tx = _jdb.tx(true).borrow_mut().as_ref().map_err(|e| actix_web::http::StatusCode::BAD_REQUEST);
| ^^^^ cannot borrow as mutable

[E0596] cannot borrow data in an Arc as mutable.
[Note] cannot borrow as mutable

@pjtatlow
Copy link
Owner

pjtatlow commented Feb 9, 2021

Have you tried getting rid of the borrow_mut and as_ref?

@ArunGust
Copy link
Author

Yes, below error popup

cannot borrow data in an Arc as mutable
trait DerefMut is required to modify through a dereference, but it is not implemented for Arc<DB>rustcE0596
[E0596] cannot borrow data in an Arc as mutable.
[Note] cannot borrow as mutable
[E0596] cannot borrow data in an Arc as mutable.
[Note] cannot borrow as mutable
[E0596] cannot borrow data in an Arc as mutable.
[Note] cannot borrow as mutable

@pjtatlow
Copy link
Owner

Hmm, looks like actix_web wraps anything in Data in an Arc. Let me take a look and see what I can come up with.

@ArunGust
Copy link
Author

Thank you

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

No branches or pull requests

2 participants