#![feature(unboxed_closures)]
#![feature(fn_traits)]
struct foo;
impl std::ops::Add for foo {
type Output = foo;
fn add(self, x: foo) -> foo {
println!("Add for foo");
x
}
}
impl Fn for foo {
extern "rust-call" fn call(&self) -> Self {
println!("Call for Foo ");
self
}
}
fn main() {
let x = foo;
let y = foo;
x + y;
x();
}
Run Code Online (Sandbox Code Playgroud)
我实现了Add特性,但我不明白如何将结构作为函数调用.我收到错误:
error[E0243]: wrong number of type arguments: expected 1, found 0
--> src/main.rs:14:10
|
14 | impl …Run Code Online (Sandbox Code Playgroud) struct Test;
// here must be code to overload the standard field resolution methods
fn main() {
let t = Test;
println!("I wanna catch request for unknown struct field {}", t.unexpected_field)
}
Run Code Online (Sandbox Code Playgroud)