I noticed that in my projects, I use a lot of String types where I don't really mean Strings, but specific types of values contained within a String, that can't be told apart e.g. by using regular expressions, but should be differentiated from a code perspective. Is there a way to make compiler help me? For example, consider this function:
fn do_something(val1: String, val2: String) {}
fn main() {
let val1: String = "hello";
let val2: String = "hello2";
do_something(val1, val2);
}
Is there a way to create SpecificStringType1 and SpecificStringType2 so the first do_something call compiles, but the second doesn't?
fn do_something(val1: SpecificStringType1, val2: SpecificStringType2) {}
fn main() {
let val1: SpecificStringType1 = "hello";
let val2: SpecificStringType2 = "hello2";
let val3: SpecificStringType2 = "hello2";
let val4: SpecificStringType2 = "hello2";
do_something(val1, val2);
do_something(val3, val4);
}