Skip to main content

length

Trait length 

Source
pub trait length {
    // Provided method
    fn __len(&self) -> number { ... }
}
Expand description

Metamethod controlling the length operator.

Provided Methods§

Source

fn __len(&self) -> number

The length (#) operation. If the value is not a string and its metatable defines __len, that metavalue is called with the value as argument and its result becomes the length.

§Examples
local t = setmetatable({}, { __len = function() return 42 end })
print(#t)    --> 42

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§