Howdy,
Let's say I'm implementing a trait, but one of more of the functions is unimplemented!() for my struct, because, let's say, it makes no sense in this particular case. However, I'd like to safeguard myself and others who use my library from a case in which they call this function in some edge case.
Can I put something in my trait implementation for this method, similar to unimplemented!(), but that instead would check during compilation whether anywhere in the codebase this function is called from this struct?
Not aware of anything like that. If a feature like that existed, it would need to work through generics and more crucially, type erasure which basically makes it impossible.
Do you have control over the trait? Can you use a different trait? The real problem is either MyTrait or MyStruct is defined incorrectly.
I guess this could be done with supertraits, having MyStruct implement the supertrait with the partial functionality that fits all cases and extend it. But that would be punishing the much more common scenario when all the functions need to be implemented, because then for all other structs there would have to be two impls.