pub trait callable {
// Provided method
fn __call(&self, args: Repeatable<any>) -> Repeatable<any> { ... }
}Expand description
Metamethod making a value callable.
Provided Methods§
Sourcefn __call(&self, args: Repeatable<any>) -> Repeatable<any>
fn __call(&self, args: Repeatable<any>) -> Repeatable<any>
The call operation f(args). Invoked when Lua tries to call a
non-function value: its __call metavalue is called with the
value itself as the first argument, followed by the original
arguments.
§Examples
local counter = setmetatable({ n = 0 }, {
__call = function(self)
self.n = self.n + 1
return self.n
end,
})
print(counter(), counter(), counter()) --> 1 2 3Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".