Both 1 and 3 would provide full compile-time type safety, at the expense of being a bit more horrible than 2. I think I'm leaning towards 1, but I don't have strong feelings about any of them. Having thought about this now though, in response to your question (thanks!), I definitely think that we should do something here better than what I presented in these patches.
I'd be very curious to hear your thoughts.
I think that options 1 or 3 are the best choices. My only qualm with option 1 is that it uses a callback. I can't even really explain *why* I don't like callbacks (maybe because I had a bad time trying to use them within Rust before, when I was lacking experience), but it just feels somehow wrong to me. (Maybe it's also because I stereotype callbacks to C -- which isn't necessarily a bad thing -- but it would certainly make me happier to find a more Rust-y way to approach this.)
Thinking about it for a little bit longer, I'm leaning a bit more towards option 3, just because I think it would be a better idea to associate a trait and a socket type. My gut feeling (keeping in mind my very brief knowledge of traits, and even less in that of callbacks) is that this would end up being nicer to implement, though maybe not as simple.
In the time since I last posted, I've been leaning towards option 1. But I don't really like callbacks either. I think the main reason for me is that then it's not really obvious what the function _does_. It some cases (if the callback returned false) it wouldn't actually do anything at all, which feels a bit weird. What would a good name for such a function be? It becomes very difficult. On the other hand, making every enum variant a struct of its own feels like a hack around a limitation of Rust, and it's a lot of boilerplate. The size of the change puts me off it. I think I'll probably have to try both out and see what feels best.
You might also be interested in implementing one of them. Would be a good starter crosvm exercise. It's probably the type of thing where you could be pretty confident you'd got it right if it compiled, but I could offer some guidance on testing it as well, if you wanted. If not, though, please give me your thoughts on approach anyway, and I'll implement whichever one we think is best myself at some point. :)
Although I would be interested in implementing one of them (#3, specifically), time is not on my side at the moment. I've recently started my first 40-hour-per-week job, so I'd like to adjust to that schedule before I really start doing things again.
Oh, congratulations! Definitely let yourself adjust to the job as a priority!
I'll definitely wait longer to push crosvm patches in future, now that I know somebody might be looking at them!
Don't worry about it; it's because I took so long to respond. :P
Didn't you respond, like, the next day? :P
P.P.S. Thanks for going into such detail in all your responses (and apologies for not doing the same)!
No worries! It was really useful to have somebody on the other end to go into detail to, because otherwise I wouldn't have thought about this so much and come to the decision I did.