#E0052: value is not callable
Functions, closures and fn values can be called, and values whose type implements ops::Call. Check that the name refers to a function, not a value of the same name.
nabi
let total = 3;
println(f"{total(1)}");
error[E0052]: a value of type `i64` is not callable --> main.nabi:2:12 | 2 | println(f"{total(1)}"); | ^^^^^^^^
Call a function or closure:
nabi
let total = |x: i32| x + 3;
println(f"{total(1)}");
4
A type of your own becomes callable through ops::Call; the error's help shows the impl. One argument arrives as itself, several as a tuple:
nabi
struct Line { a: f64; b: f64; }
impl ops::Call<f64> for Line {
type Output = f64;
fn call(self, x: f64) -> f64 { self.a * x + self.b }
}
let l = Line { a: 2.0, b: 1.0 };
println(f"{l(3.0)}");
7
Related: E0047 item used in the wrong form
Found a mistake? Edit this page on GitHub. Last updated