I'm guessing that Integer, Decimal and Float will actually have values attached. And as @khimru said, enum variants are not types, so these need to be structs. And T in ContinuousControlPort needs a trait bound in order to constrain the type of its fields.
The way I know how to do it is something like this (I've added a sub-module to make the naming less redundant):
mod continuous_port {
pub trait Type {}
pub struct Integer(pub i64);
pub struct Decimal(pub i64, pub u8);
pub struct Float(pub f64);
impl Type for Integer {}
impl Type for Decimal {}
impl Type for Float {}
}
struct ContinuousControlPort<T: continuous_port::Type> {
max: T,
min: T,
default: T,
logarithmic: bool,
}
let cp = ContinuousControlPort {
min: continuous_port::Integer(10),
max: continuous_port::Integer(20),
default: continuous_port::Integer(10),
logarithmic: false,
};
Edit: fixed module naming.
Or if you don't want to wrap the built-in integer and float types in a struct:
mod continuous_port {
pub trait Type {}
impl Type for i64 {}
impl Type for (i64, u8) {}
impl Type for f64 {}
}
struct ContinuousControlPort<T: continuous_port::Type> {
max: T,
min: T,
default: T,
logarithmic: bool,
}
let cp: ContinuousControlPort<i64> = ContinuousControlPort {
min: 10,
max: 20,
default: 10,
logarithmic: false,
};
Or the same as above but without the sub-module:
trait ContinuousPortType {}
impl ContinuousPortType for i64 {}
impl ContinuousPortType for (i64, u8) {}
impl ContinuousPortType for f64 {}
struct ContinuousControlPort<T: ContinuousPortType> {
max: T,
min: T,
default: T,
logarithmic: bool,
}
let cp = ContinuousControlPort::<i64> {
min: 10,
max: 20,
default: 10,
logarithmic: false,
};