What is the lowest runtime-overhead way of “naming” a list of tuples in Rust?

  Kiến thức lập trình

I’m getting slightly lost in Rust compiler semantics, but am attempting to find the lowest cost way of simply referring to an array of tuples of numbers by some name for each field and passing that around between functions. More concretely, I am receiving from an external source a list of the form [(f64, f64, f64)], each of which has a name. I want to be able to refer to the fields by name but without converting them to some additional type (unless that is zero cost).

e.g. I could run through and wrap them into:

struct NameStruct {
   foo: f64,
   bar: f64,
   baz: f64,
}

however I presume that would have a cost of running through the array and wrapping them? Whereas a type alias seems like one cannot name individual fields within it.

I’m sure there’s something simple I’m missing!

LEAVE A COMMENT