ModularM
Modular2y ago
5 replies
jmky

Conditional typing of fields.

Suppose I have the following struct: (in pseudo Mojo)

struct IntWrapper[N: Int]:
    @parameter
    if N <= 255:
        var inner: UInt8
    else:
        var inner: Int


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?
Was this page helpful?