Length
trait Length<T>
Source: compiler/src/builtin_docs/prelude/ops.hy A size query: x.len().
Arrays, Vec, strings (UTF-8 bytes), tuples and records (fields) have a
structural length and need no instance; fixed sizes fold at compile time.
They meet a T: Length bound too, len reading that same length.
Implement Length to give your own type a length.
Required methods#
| Name | Description |
|---|---|
len | Returns the length of value. |
Examples#
use tests::assert;
class Team {
pub names: Vec<string>,
}
impl Length for Team {
pub fn len(Team t) -> int {
return t.names.len();
}
}
fn main() {
let t = new Team(Vec::from(["ana", "bo"]));
assert!(t.len() == 2);
}