I'm getting a lifetime error on this bit of code and I'm lost as what todo.
error[E0308]: mismatched types
--> avtor-cli/src/main.rs:22:9
|
22 | create_super_user(this_find_super_user, this_insert_user, user_dto).await;
| ^^^^^^^^^^^^^^^^^ lifetime mismatch
|
::: /home/decapo01/projects/avtor-rs/avtor-core/src/models/users.rs:193:6
|
193 | ) -> impl FnOnce(&'a User) -> BoxFuture<'a, Result<(), CreateSuperUserError>> {
| ------------------------------------------------------------------------
| |
| the expected opaque type
| the found opaque type
|
= note: expected associated type `<impl FnOnce(&User)-> Pin<Box<dyn Future<Output = Result<(), CreateSuperUserError>> + Send>> as FnOnce<(&User,)>>::Output`
found associated type `<impl FnOnce(&User)-> Pin<Box<dyn Future<Output = Result<(), CreateSuperUserError>> + Send>> as FnOnce<(&User,)>>::Output`
note: the lifetime requirement is introduced here
--> /home/decapo01/projects/avtor-rs/avtor-core/src/models/users.rs:233:35
|
233 | insert: impl FnOnce(&User) -> FB,
| ^^
this is the offending function
pub async fn create_super_user<FA, FB>(
find_super_user: impl FnOnce() -> FA,
insert: impl FnOnce(&User) -> FB,
user_dto: &UserDto,
) -> Result<(), CreateSuperUserError>
where
FA: Future<Output = Result<Option<User>, CreateSuperUserError>>,
FB: Future<Output = Result<(), CreateSuperUserError>>,
{
let _ = user_dto.validate().map_err(|e| {
let hash_map = hash_map_from_validation_errors(e);
CreateSuperUserError::UserInvalid(hash_map)
})?;
let user = user_from_dto(user_dto.clone());
let maybe_existing_user = find_super_user().await?;
match maybe_existing_user {
Some(_) => Err(CreateSuperUserError::SuperUserExists),
None => {
let ins_res = insert(&user).await;
match ins_res {
Ok(_) => Ok(()),
Err(e) => Err(e)
}
},
}
}
I'm injecting in two other functions and this is what they look like set up
async fn _create_super_user(client: Client, user_dto: &UserDto) {
let this_insert_user = insert_user(&client);
let this_find_super_user = find_super_user(&client);
let x =
create_super_user(this_find_super_user, this_insert_user, user_dto).await;
()
}