-
Notifications
You must be signed in to change notification settings - Fork 106
Improving Interface
data structure by using generic data type
#2727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
After this, we can introduce impl Interface<T> where T: Controller {
fn validate_port_over_book(&self) -> Result<(), NmstateError> {
for port_name in self.specifc.ports().unwrap_or_default() {
validate_over_book(port_name)?;
}
Ok(())
} This would remove a lot duplicate code and provide better code layout. |
With Still searching for better approaches. |
I have been thinking about this recently too. The problem that I see with the current approach is that Interface being an enum forces us to do Something more similar to using Interfaces and/or polymorphism would be desirable. It would allow to comply with the "Open-Closed principle" much more, too. For example, all interface types implementing an The problem with that is: how to convert to the specific interface type from the I've seen that For the moment, the 2 things that I think that would be nice are (both can be used at the same time):
|
Today I have been experimenting about this. Those 2 things that I initially planned to do don't work, actually, for an obvious reason: they are still static dispatch, so obviously you cannot use them from a dynamically dispatched type. Using Here I have 3 small test projects summarizing the different ways that I've found that can work: https://github.com/ihuguet/rust-poly |
Demo code:
The text was updated successfully, but these errors were encountered: