我想调用为类型实现的方法&[i32]
我可以通过类型别名做得一样所示的线标记为1,但有可能在不引入每次一个类型别名?
trait Foo<T> {
fn say_hi(x: T);
}
impl<'a> Foo<i32> for &'a [i32] {
fn say_hi(x: i32) {}
}
type Array<'a> = &'a [i32];
fn main() {
let arr = [1, 2, 3];
Array::say_hi(1);//line 1
&[i32]::say_hi(1);//line 2
}
标记2的线产生的错误消息:
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
--> /home/xxx/.emacs.d/rust-playground/at-2017-08-09-051114/snippet.rs:21:11
|
21 | &[i32]::say_hi(1);
| ^^ expected one of `.`, `;`, `?`, `}`, or an operator here
error[E0423]: expected value, found builtin type `i32`
--> /home/xxx/.emacs.d/rust-playground/at-2017-08-09-051114/snippet.rs:21:7
|
21 | &[i32]::say_hi(1);
| ^^^ not a value
是否有可能修改线条为标志2没有编译错误?