myClass m;
void Foo(){
m = new myClass(){
@Override
public void method(String x){...}
};
}
}
abstract class myClass{
void method(String x);
void readFile(){
*reads a file*
String fileContent = the file content
method(fileContent);
}
}
so with this I can maintain a list of instances of
myClass
like list.add(m)
is there anyway I can do the same in rust?
my end goal is whenever I receive message over websocket it stores it in local file and then it reads the file and send updated file content to all the users listening to it.
so what I did in java is maintained a list of instances of the class and whenever the file was updated the readFile method was called for all instances and which ultimately calls the method which was Overrided by different classes. I want to do
traits
Don’t think in Java while you write rust
Обсуждают сегодня