pub trait tostring {
// Provided methods
fn __tostring(&self) -> string { ... }
fn __name(&self) -> string { ... }
}Expand description
Metamethods controlling string conversion.
Provided Methods§
Sourcefn __tostring(&self) -> string
fn __tostring(&self) -> string
Invoked by tostring() (and therefore by
print) to convert the value to a string.
§Examples
local pt = setmetatable({ x = 1, y = 2 }, {
__tostring = function(p) return "(" .. p.x .. ", " .. p.y .. ")" end,
})
print(pt) --> (1, 2)Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".