Perseids
Perseids

Reputation: 13220

What is the Rust equivalent of `size_t`?

In more practical terms: What integer data type should I use for indices in a vector, length of arrays, etc?

There are lots of discussions on this topic for pre-1.0 Rust floating around on the internet and I can't find an authoritative answer on the final decision.

Upvotes: 15

Views: 9370

Answers (1)

filmor
filmor

Reputation: 32182

That would be usize and isize (pointer-size types, unsigned and signed). The reference says that the maximal size of an array is the maximum value of isize such that differences of positions can be calculated.

The functions of std::Vec use usize for all indices, though.

Upvotes: 19

Related Questions