#Beginner needs help with generics

3 messages · Page 1 of 1 (latest)

vestal comet
#

So I have this enum called OrientationKind with two possible values, which map to essentially collections of floats inside an Orientation struct. I'd like to be able to get the values as collections of either f16s, f32s or f64s so I tried using generics, but I must be doing something wrong since I get a compiler error: Parameter T is never used on the Enum...

tulip sluice
#

You can pass T into the enum like this:

  pub enum OrientationKind<T> {
    Pointy(T),
    Flat(T),
  }
#

You can also use as to convert f64 to f32 and vise versa but if you convert from f64 to f32 you may lose some accuracy.