I have following function
pub async fn update_user<T>(
&mut self,
uid: impl AsRef<str>,
fields: &[(impl AsRef<str>, &T)],
) -> UnitResult
where
T: ToSql + Sync,
{
let (keys, values): (Vec<_>, Vec<_>) =
fields.iter().map(|&(k, v)| (k.as_ref(), v)).unzip();
let query_set = keys
.iter()
.enumerate()
.fold(String::new(), |qs, (i, curr)| {
if i == 0 {
format!("{}=${}", curr, i + 1)
} else {
format!("{}, {}=${}", qs, curr, i + 1)
}
});
let query = format!(
r#"update users set {} where "id"='{}'"#,
query_set,
uid.as_ref()
);
self.client
.clone()
.get()
.await
.map_err(str_err!(Err::ConnErr))?
.execute(query.as_str(), values.as_slice())
.await
.map_err(str_err!(Err::DBErr))
.map(|_| ())
}
and I get the following error
Here
T
is both sync and ToSql so why It is complaining I dont understand the functions asks for a &ToSql+Sync
and I am giving it the same thing but for some reason compiler cannot figure out that the T is the same thingWhy does this happen ?