I have some code similar to this
enum Value<'a> {
Int(i64),
Flt(f64),
Vec(&'a [Value<'a>]),
}
and this lets me reuse some data; however, some times I want to accept heap-allocated data, so I would need something like this
enum Value {
Int(i64),
Flt(f64),
Vec(Box<Vec<Value>>),
}
but now I cannot accept slices! I know I could always have both of them in the same enum, like this
enum Value<'a> {
Int(i64),
Flt(f64),
VecSlice(&'a [Value<'a>]),
VecBox(Box<Vec<Value<'a>>>),
}
but this is very ugly.
Is there a way to have a struct or enum that accepts both slices and vectors in the same member/variant?
I know that for functions accepting &str and String we can just set the parameters to something like T: Into<String> but I have not figured out how to do something like this for vectors inside data types.