My current idea is this:
struct Foo { // A Foo
bars: Vec<Bar>, // The Foo's Bars
type_: FooType, // What kind of Foo it is
}
struct FooType { // A kind of Foo
mandatory_bars: Vec<BarType>,
optional_bars: Vec<BarType>,
}
struct BarType { // A kind of Bar
name: String, // The name of the kind of Bar
type_: BarValueType, // What type the value of the Bar should have
}
enum BarValueType { // The type of the value of a Bar
Int,
Float,
String,
// etc.
}
struct Bar { // A Bar
type_: BarType, // What kind of Bar it is
value: todo!(), // The value of the Bar; but how do I represent the type?
}
The problem with this is that I can't represent the value of a Bar
. AFAIK there is no Any
type that I can use to dynamically check if the types match, and I don't think I can somehow make it only accept the type that the BarType
wants. How can I refactor this so it works with the type system?