Skip to content

mismatched types and web:Data<> problem when called from different file #2342

Answered by aliemjay
Leanerz asked this question in Q&A
Discussion options

You must be logged in to vote

In add_user, cgrpc is of type Data. You can only get &APIClient<_> from it by either using Data::get_ref or by Deref trait and deref coercion. However, you should modify AddUsers to receive a &APIClient, instead of APIClient (or you can clone it!).

Here is an example.

Modify AddUsers:

pub async fn AddUsers(cgrpc: &APIClient<tonic::transport::Channel> ...

in add_user (you also need to await):

AddUsers(cgrpc.get_ref(), 1).await;
//  or by deref coercion
AddUsers(&cgrpc, 1).await;

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@Leanerz
Comment options

@robjtede
Comment options

@Leanerz
Comment options

@robjtede
Comment options

@Leanerz
Comment options

Answer selected by robjtede
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2341 on July 22, 2021 19:30.