如何删除`let _ :()= ...`?

时间:2016-06-24 05:51:53

标签: rust

这是我的代码,这有效:

//...

fn main() {
    let con : redis::Connection = establish_connection();
    redis::cmd("RANDOMKEY").query(&con).unwrap();
}

但是这个不起作用:

error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
    redis::cmd("FLUSHALL").query(&con).unwrap();
                           ^~~~~
help: run `rustc --explain E0282` to see a detailed explanation

编译时会引发错误:

let _ : () = ...

我必须写<ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" > <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true" > </HorizontalScrollView> </ScrollView> 吗?我该如何删除它?

1 个答案:

答案 0 :(得分:4)

redis::Cmd::query定义为:

fn query<T: FromRedisValue>(&self, con: &ConnectionLike) -> RedisResult<T>

您只需要在此处T ()获得与将query(...).unwrap()的值注释为T相同的行为。这应该有效:

redis::cmd("RANDOMKEY").query::<()>(&con).unwrap();