That's not regarding Copy
trait. I thought about it while designing API, where different requests have same fields. I don't want to copypaste declarations (since that would require copy-pasting & later synchronising e.g. validations), but don't want to use same types for different interfaces to prevent occasional confusion. But it's really generic problem. Here's the illustration.
We have two structs:
struct DataCreateRequest {
name: String
// ... 100 more fields
}
struct DataUpdateRequest {
name: String
// ... 100 more fields
}
What I would like to do is similar to type
aliasing, but to make types distinct, something like this:
struct DataCreateRequest {
name: String
// ... 100 more fields
}
clone_type DataUpdateRequest = DataCreateRequest; // could be some macro?
let upd: DataUpdateRequest = DataCreateRequest { ... }; // compiler error, since those are different types
So that we reduce duplication, and still re-specialise them if different request appears later.
Any ideas? Any trait, wrapper, macro magic comes to mind?:)