Hello!
I'm just starting out with Rust. Hell of a trip. Fun so far! Excuse the language.
I'm trying to make my own little recursive data structure, and I'm struggling with two things.
#[derive(Clone, Eq, PartialEq, Hash)]
enum TestStructure {
Desc(String),
Number(i64),
//Visibility(f64),
Row(Vec<TestStructure>),
Table(HashMap<TestStructure, TestStructure>),
}
First, I want to mix some float in there, but due to the limitations inherent in dealing with floats, that seems hard to do. What's the best way to resolve this? Do I create custom implementations for all of them, or can I selectively implement traits for Visibility only?
Let's say that it makes sense for me to do so, and I'd be happy to define what equality and hashing of floats means in my particular domain.
Alternatively, I may be convinced to not use floats as keys in the map. In this case, how would I disallow floats as keys (but still use them as values), allowing the rest of them to be keys and/or values, and yet have them all remain the same type?
Secondly, let's say that I have two versions of this structure in mind, one that makes sense when data arrives externally, one that makes sense when it is generated internally in the program. One is a subset of the other—the internal one is allowed one super special entry into the enum that can't be allowed with data arriving from the outside, for security reasons. Otherwise they're identical.
Can I define the subset enum and extend it as a new enum (or vice versa)? Or do I have to reimplement most of the enum twice?