Conditional typing of fields.
Suppose I have the following struct: (in pseudo Mojo)
For usecases where I know that it is definite that the field
inner
cannot hold values larger than N
, then is it possible to type the fields conditionally?
You can do this easily in C++, impossible to do in Rust.
What about Mojo?1 Reply
I don’t think this is currently supported by a do really like the idea, the closest is can think of is something like this
Alternatively you could have the struct take in a type as a parameter, along with N, and figure that out as a separate function
The code will be a little messier but you don’t have to do type gymnastics with traits and can just return the passed in type
you have to define an init function but those are the two easiest ways I can think of implementing what your asking